﻿// Decompiled with JetBrains decompiler
// Type: DnProcessSimulateCommands.RobotJog.CUiRJRobotJogWindow
// Assembly: DnProcessSimulateCommands, Version=2402.0.0.890, Culture=neutral, PublicKeyToken=null
// MVID: A885D881-AEDF-447E-852A-6F13102E089C
// Assembly location: C:\Program Files\Tecnomatix_2402\eMPower\DotNetCommands\DnProcessSimulateCommands.dll

using DnProcessSimulateCommands.RobotJog.Controls;
using DnProcessSimulateCommands.RobotJog.Controls.Joints;
using EngineeringInternalExtension;
using System;
using System.CodeDom.Compiler;
using System.Collections;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Diagnostics;
using System.Linq;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Controls.Primitives;
using System.Windows.Forms;
using System.Windows.Forms.Integration;
using System.Windows.Input;
using System.Windows.Interop;
using System.Windows.Markup;
using System.Windows.Media;
using Tecnomatix.Engineering;
using Tecnomatix.Engineering.Ui;
using Tecnomatix.Engineering.Ui.WPF;
using UiInternalControls.WPF;
using UiInternalControls.WPF.JointJogControls;


namespace DnProcessSimulateCommands.RobotJog;

public class CUiRJRobotJogWindow : TxWindow, IComponentConnector
{
  public CApRJRobotJogManipulationLogic _manipulationLogic;
  private CApRJRobotJogJointsLogic _jointJogLogic;
  private CApRJRobotJogFrameLogic _frameLogic;
  private TxFrameComboBoxCtrl _frameComboBoxCtrl;
  private int _btnSetExternalValuesNumberOfClicks;
  private int _btnTeachLocationNumberOfClicks;
  private bool _loadingWindow = true;
  private bool _wasForcedToClose;
  private bool _restoreOriginalValues;
  private readonly CApRJSRobotsManager _robotsManager;
  private readonly string _robotRoleOptionMaster = RJRobotJogResources.MASTER_ROLE_ROBOT;
  private readonly string _robotRoleOptionSlave = RJRobotJogResources.SLAVE_ROLE_ROBOT;
  private readonly string _robotRoleOptionNone = RJRobotJogResources.NO_ROLE_ROBOT;
  private bool _isMasterSlaveModeIsNotTakingInAccount = true;
  private bool _dontStoreRobotInfo;
  private int _disableTCPTrackingOnBeforeJointValueChange;
  private bool? _savedLockTCPF;
  private bool _addLocationSuccessFlag = true;
  private bool _disableTCPFMovementByTcpfLockButton;
  private bool _clearNotificationAtNextLocationNavigation;
  private ITxLocationOperation _prevLocationForNotification;
  private readonly ITxRoboticLocationOperation _initialLocation;
  private ITxRoboticLocationOperation _addedLocation;
  private bool _isTeachLocationClicked;
  private CApRJRobotJogGhostGunDisplayer _gunDisplayer;
  private bool _notifyFromManipulator;
  private bool m_continuousTransactionRunning;
  private string _frameComboBoxMovingObjId;
  public static readonly DependencyProperty ManipulateWeldRoboticLocationsProperty = DependencyProperty.Register(nameof (ManipulateWeldRoboticLocations), typeof (bool), typeof (CUiRJRobotJogWindow));
  public static readonly DependencyProperty ManipulateSeamRoboticLocationsProperty = DependencyProperty.Register(nameof (ManipulateSeamRoboticLocations), typeof (bool), typeof (CUiRJRobotJogWindow));
  public static readonly DependencyProperty CompoundEquipmentProperty = DependencyProperty.Register(nameof (CompoundEquipment), typeof (ITxObjectCollection), typeof (CUiRJRobotJogWindow));
  internal Grid m_compoundPanel;
  internal TxObjectComboBoxCotrol currentRobot;
  internal System.Windows.Controls.ComboBox ddRobotMasterSlaveRole;
  public ToggleButton btnLockTCPF;
  internal System.Windows.Controls.Image btnLockTCPF_img;
  public TxToolbarSplitButton btnEnableRobotPlacement;
  internal ToggleButton btnShowDependentJoints;
  internal System.Windows.Controls.Image btnShowDependentJoints_img;
  internal System.Windows.Controls.Button btnResetToHardLimits;
  internal System.Windows.Controls.Image btnResetToHardLimits_img;
  internal System.Windows.Controls.Button btnResetAllSoftLimits;
  internal System.Windows.Controls.Image btnResetAllSoftLimits_img;
  internal ToggleButton btnSetExternalAxes;
  internal System.Windows.Controls.Image btnSetExternalAxes_img;
  internal System.Windows.Controls.Button btnClearExternalAxes;
  internal System.Windows.Controls.Image btnClearExternalAxes_img;
  internal ToggleButton btnTeachLocation;
  internal System.Windows.Controls.Image btnTeachLocation_img;
  internal System.Windows.Controls.Button btnClearTaughtLocation;
  internal System.Windows.Controls.Image btnClearTaughtLocation_img;
  internal System.Windows.Controls.Button btnMoveToTCPF;
  internal System.Windows.Controls.Image btnMoveToTCPF_img;
  internal System.Windows.Controls.Button btnOptions;
  internal System.Windows.Controls.Image btnOptions_img;
  public ToggleButton btnMasterSlaveMode;
  internal System.Windows.Controls.Image btnMasterSlaveMode_img;
  internal Expander LocationNavigationExpander;
  internal UiInternalControls.WPFControls.TxLocationNavigationControl.TxLocationNavigationControl txLocationNavigationControl;
  internal ToggleButton btnFollowMode;
  internal System.Windows.Controls.Image btnFollowMode_img;
  internal System.Windows.Controls.Button btnAddLocationBefore;
  internal System.Windows.Controls.Image btnAddLocationBefore_img;
  internal System.Windows.Controls.Button btnAddLocationAfter;
  internal System.Windows.Controls.Image btnAddLocationAfter_img;
  internal System.Windows.Controls.ComboBox comboCopyParameters;
  internal TxMessageBar warningMessageBar;
  internal Expander ManipulationExpander;
  internal TxPlacementCollisionControl txManManipulationControl;
  internal WindowsFormsHost frameComboBoxCtrlHost;
  internal TextBlock lblConfigurationCaption;
  internal System.Windows.Controls.ComboBox ddlConfiguration;
  public ToggleButton btnLockConfiguration;
  internal System.Windows.Controls.Image btnLock_img;
  internal Expander ExternalJointsExpander;
  internal CUiJointsControl jointsBlock;
  internal Expander AllJointsBlockExpander;
  internal Expander CoordinateReferenceBlock;
  internal CUiCoordinateReference txCoordinateReference;
  internal System.Windows.Controls.Button btnReset;
  internal System.Windows.Controls.Button btnClose;
  private bool _contentLoaded;

  public bool WasForcedToClose => this._wasForcedToClose;

  public ITxObjectCollection CompoundEquipment
  {
    get
    {
      return (ITxObjectCollection) ((DependencyObject) this).GetValue(CUiRJRobotJogWindow.CompoundEquipmentProperty);
    }
    set
    {
      ((DependencyObject) this).SetValue(CUiRJRobotJogWindow.CompoundEquipmentProperty, (object) value);
    }
  }

  public CopyParametersOptions CopyParametersOption
  {
    get => (CopyParametersOptions) this.comboCopyParameters.SelectedValue;
    set => this.comboCopyParameters.SelectedIndex = (int) value;
  }

  public static bool? IsLocationAddedBefore { get; set; }

  public bool CopyAttachmentSetting { get; set; }

  public bool DisplayGhostGun { get; set; }

  public bool ManipulateWeldRoboticLocations
  {
    get
    {
      return (bool) ((DependencyObject) this).GetValue(CUiRJRobotJogWindow.ManipulateWeldRoboticLocationsProperty);
    }
    set
    {
      ((DependencyObject) this).SetValue(CUiRJRobotJogWindow.ManipulateWeldRoboticLocationsProperty, (object) value);
    }
  }

  public bool ManipulateSeamRoboticLocations
  {
    get
    {
      return (bool) ((DependencyObject) this).GetValue(CUiRJRobotJogWindow.ManipulateSeamRoboticLocationsProperty);
    }
    set
    {
      ((DependencyObject) this).SetValue(CUiRJRobotJogWindow.ManipulateSeamRoboticLocationsProperty, (object) value);
    }
  }

  public CUiRJRobotJogWindow(ITxObject manipulatedObject)
  {
    this.InitializeComponent();
    this.InitCopyParamatersList();
    // ISSUE: explicit non-virtual call
    if (double.IsNaN(__nonvirtual (((FrameworkElement) this).Width)))
    {
      // ISSUE: explicit non-virtual call
      __nonvirtual (((FrameworkElement) this).Width) = ((FrameworkElement) this).MinWidth;
    }
    // ISSUE: explicit non-virtual call
    if (double.IsNaN(__nonvirtual (((FrameworkElement) this).Height)))
    {
      // ISSUE: explicit non-virtual call
      __nonvirtual (((FrameworkElement) this).Height) = ((FrameworkElement) this).MinHeight;
    }
    this._initialLocation = manipulatedObject as ITxRoboticLocationOperation;
    string str = string.Empty;
    if (this._initialLocation != null)
    {
      if (CUiRJRobotJogWindow.IsLocationAddedBefore.HasValue)
      {
        try
        {
          str = this.CopyParametersAndAttachment(this._initialLocation);
        }
        finally
        {
          CUiRJRobotJogWindow.IsLocationAddedBefore = new bool?();
        }
      }
    }
    this._manipulationLogic = new CApRJRobotJogManipulationLogic(manipulatedObject, new UpdateDelta(this.UpdateManipulatorControl), new DnProcessSimulateCommands.RobotJog.ResetManipulatorControl(this.ResetManipulatorControl), new ForceExit(this.Exit), new TxObject_DeletedEventHandler(this.Object_Deleted));
    this.RegisterManipulationLogicEvents();
    this.InitGhostGun(manipulatedObject);
    this.ManipulateWeldRoboticLocations = CApRJRobotJogUtilities.IsWeldLocationManipulationEnabled;
    this.ManipulateSeamRoboticLocations = CApRJRobotJogUtilities.IsSeamLocationManipulationEnabled;
    if (!string.IsNullOrEmpty(str))
    {
      ((ContentControl) this.warningMessageBar).Content = (object) str;
      this.warningMessageBar.MessageType = (MessageType) 1;
      ((UIElement) this.warningMessageBar).Visibility = Visibility.Visible;
      this._clearNotificationAtNextLocationNavigation = true;
    }
    this.btnLockTCPF_img.Source = TxImageManager.GetImageByKey("LockTcpf").ConvertTo<ImageSource>(new System.Drawing.Size());
    this.btnEnableRobotPlacement.DropDownList[0].Icon = TxImageManager.GetImageByKey("EnableRobotPlacement").ConvertTo<ImageSource>(new System.Drawing.Size());
    this.btnEnableRobotPlacement.DropDownList[1].Icon = TxImageManager.GetImageByKey("EnableRobotAndAttachmentChainPlacement").ConvertTo<ImageSource>(new System.Drawing.Size());
    this.btnShowDependentJoints_img.Source = TxImageManager.GetImageByKey("ShowDependentJoints").ConvertTo<ImageSource>(new System.Drawing.Size());
    this.btnResetToHardLimits_img.Source = TxImageManager.GetImageByKey("ResetSelectedLimitToHardLimits").ConvertTo<ImageSource>(new System.Drawing.Size());
    this.btnResetAllSoftLimits_img.Source = TxImageManager.GetImageByKey("ResetAllLimitsToHardLimits").ConvertTo<ImageSource>(new System.Drawing.Size());
    this.btnSetExternalAxes_img.Source = TxImageManager.GetImageByKey("SetExternalAxesValues").ConvertTo<ImageSource>(new System.Drawing.Size());
    this.btnClearExternalAxes_img.Source = TxImageManager.GetImageByKey("ClearExternalAxesValues").ConvertTo<ImageSource>(new System.Drawing.Size());
    this.btnTeachLocation_img.Source = TxImageManager.GetImageByKey("TeachLocation").ConvertTo<ImageSource>(new System.Drawing.Size());
    this.btnClearTaughtLocation_img.Source = TxImageManager.GetImageByKey("ClearTeachLocation").ConvertTo<ImageSource>(new System.Drawing.Size());
    this.btnMoveToTCPF_img.Source = TxImageManager.GetImageByKey("MoveLocationToTcpf").ConvertTo<ImageSource>(new System.Drawing.Size());
    this.btnOptions_img.Source = TxImageManager.GetImageByKey("Settings").ConvertTo<ImageSource>(new System.Drawing.Size());
    this.btnMasterSlaveMode_img.Source = TxImageManager.GetImageByKey("EnableLeaderFollowerMode").ConvertTo<ImageSource>(new System.Drawing.Size());
    this.btnFollowMode_img.Source = TxImageManager.GetImageByKey("FollowMode").ConvertTo<ImageSource>(new System.Drawing.Size());
    this.btnAddLocationBefore_img.Source = TxImageManager.GetImageByKey("AddLocationBefore").ConvertTo<ImageSource>(new System.Drawing.Size());
    this.btnAddLocationAfter_img.Source = TxImageManager.GetImageByKey("AddLocationAfter").ConvertTo<ImageSource>(new System.Drawing.Size());
    this.btnLock_img.Source = TxImageManager.GetImageByKey("Lock").ConvertTo<ImageSource>(new System.Drawing.Size());
  }

  public CUiRJRobotJogWindow(ITxObject manipulatedObject, ITxObjectCollection compoundEquipment)
    : this(manipulatedObject)
  {
    this.CompoundEquipment = compoundEquipment;
    this.btnReset.Content = (object) RJRobotJogResources.RobotJogResetAll;
    this._robotsManager = CApRJSRobotsManager.the();
  }

  private void InitGhostGun(ITxObject manipulatedObject)
  {
    object obj;
    TxWindowSettings.RestoreWindowValue(typeof (CUiRJJointsOptionsForm), "DisplayGhostGun", ref obj);
    this.DisplayGhostGun = obj == null || Convert.ToBoolean(obj);
    bool fromInsideCommand = this._manipulationLogic.IsManipulationFromInsideCommand;
    this._manipulationLogic.IsManipulationFromInsideCommand = true;
    this._gunDisplayer = new CApRJRobotJogGhostGunDisplayer((ITxRobot) this._manipulationLogic.Robot);
    if (this.DisplayGhostGun)
      this._gunDisplayer.Show(manipulatedObject as ITxRoboticLocationOperation);
    this._manipulationLogic.IsManipulationFromInsideCommand = fromInsideCommand;
  }

  private void InitCopyParamatersList()
  {
    this.comboCopyParameters.ItemsSource = (IEnumerable) new List<object>()
    {
      (object) new
      {
        Value = CopyParametersOptions.None,
        Description = RJRobotJogResources.CopyParametersNoneString
      },
      (object) new
      {
        Value = CopyParametersOptions.Robotic,
        Description = RJRobotJogResources.CopyParametersRoboticString
      },
      (object) new
      {
        Value = CopyParametersOptions.RoboticAndOLP,
        Description = RJRobotJogResources.CopyParametersRoboticWithOLPString
      }
    };
    this.comboCopyParameters.DisplayMemberPath = "Description";
    this.comboCopyParameters.SelectedValuePath = "Value";
    this.comboCopyParameters.SelectedIndex = CApRJRobotJogUtilities.GetIntValueFromRegistry((TxWindow) this, CApRJRobotJogUtilities.COPY_PARAMETERS, 0);
    object obj;
    TxWindowSettings.RestoreWindowValue(typeof (CUiRJJointsOptionsForm), "CopyAttachmentValue", ref obj);
    this.CopyAttachmentSetting = obj == null || Convert.ToBoolean(obj);
  }

  private void InitRobotList()
  {
    if (this.CompoundEquipment == null)
      return;
    TxPickProvider[] txPickProviderArray = new TxPickProvider[2]
    {
      null,
      (TxPickProvider) 1
    };
    this.currentRobot.SetValidator((ITxValidator) new CApRJRobotInCompoundEquipmentValidator(this.CompoundEquipment));
    this.currentRobot.SetPickProviders(txPickProviderArray);
    this.currentRobot.PickLevel = (TxPickLevel) 1;
    this.currentRobot.ListenToPick = true;
    this.currentRobot.Focus();
    TxObjectList allDescendants = this.CompoundEquipment.GetAllDescendants((ITxTypeFilter) new TxTypeFilter(typeof (TxRobot)));
    foreach (TxRobot robot in (Collection<ITxObject>) allDescendants)
    {
      this.StoreFirstTimeRobotInfo(robot);
      this.currentRobot.AddItem(((TxBaseGeometryCreationObject) robot).Name, (ITxObject) robot);
    }
    this.currentRobot.Object = ((Collection<ITxObject>) allDescendants)[0];
    ArrayList arrayList = new ArrayList()
    {
      (object) this._robotRoleOptionNone,
      (object) this._robotRoleOptionSlave,
      (object) this._robotRoleOptionMaster
    };
    this.ddRobotMasterSlaveRole.ItemsSource = (IEnumerable) arrayList;
    this.ddRobotMasterSlaveRole.SelectedItem = arrayList[0];
  }

  private void InitFrameComboBox()
  {
    this._frameComboBoxCtrl = new TxFrameComboBoxCtrl();
    this._frameComboBoxCtrl.EnableAdvancedPick = true;
    this._frameComboBoxCtrl.ListenToPick = true;
    this._frameComboBoxCtrl.PickLevel = (TxPickLevel) 6;
    this._frameComboBoxCtrl.ValidFrameSet += new TxFrameComboBoxCtrl_ValidFrameSetEventHandler(this.frameComboBoxCtrl_ValidFrameSet);
    this._frameComboBoxCtrl.InvalidFrameSet += new TxFrameComboBoxCtrl_InvalidFrameSetEventHandler(this.frameComboBoxCtrl_InvalidFrameSet);
    this.frameComboBoxCtrlHost.Child = (System.Windows.Forms.Control) this._frameComboBoxCtrl;
    ((System.Windows.Forms.Control) this._frameComboBoxCtrl).LostFocus += new EventHandler(this.FrameComboBoxCtrl_LostFocus);
  }

  private void StoreCotrolsStates()
  {
    Dictionary<string, bool> contorolsState = new Dictionary<string, bool>()
    {
      {
        CApRJRobotJogUtilities.LOCATION_EXPANDER_EXPANDED,
        this.LocationNavigationExpander.IsExpanded
      },
      {
        CApRJRobotJogUtilities.MANIPULATION_EXPANDER_EXPANDED,
        this.ManipulationExpander.IsExpanded
      },
      {
        CApRJRobotJogUtilities.EXTERNAL_JOINTS_EXPANDER_EXPANDED,
        this.ExternalJointsExpander.IsExpanded
      },
      {
        CApRJRobotJogUtilities.ALL_JOINTS_EXPANDER_EXPANDED,
        this.AllJointsBlockExpander.IsExpanded
      },
      {
        CApRJRobotJogUtilities.COORDINATE_REFERENCE_EXPANDER_EXPANDED,
        this.CoordinateReferenceBlock.IsExpanded
      },
      {
        CApRJRobotJogUtilities.SNAP_BY_STEP_SIZE_CHECKED,
        this.txCoordinateReference.SnapToStepSize
      },
      {
        CApRJRobotJogUtilities.SHOW_DEPENDENT_JOINTS_CHECKED,
        this.btnShowDependentJoints.IsChecked.Value
      }
    };
    if (this.CompoundEquipment == null)
    {
      Dictionary<string, bool> dictionary1 = contorolsState;
      string lockTcpfChecked = CApRJRobotJogUtilities.LOCK_TCPF_CHECKED;
      bool? isChecked = this.btnLockTCPF.IsChecked;
      int num1 = isChecked.Value ? 1 : 0;
      dictionary1.Add(lockTcpfChecked, num1 != 0);
      Dictionary<string, bool> dictionary2 = contorolsState;
      string placementChecked = CApRJRobotJogUtilities.ENABLE_ROBOT_PLACEMENT_CHECKED;
      isChecked = this.btnEnableRobotPlacement.IsChecked;
      int num2 = isChecked.Value ? 1 : 0;
      dictionary2.Add(placementChecked, num2 != 0);
      contorolsState.Add(CApRJRobotJogUtilities.ENABLE_ROBOT_ATTACHMENTS_PLACEMENT_SELECTED, this.btnEnableRobotPlacement.SelectedItem == 1);
      Dictionary<string, bool> dictionary3 = contorolsState;
      string configurationChecked = CApRJRobotJogUtilities.LOCK_CONFIGURATION_CHECKED;
      isChecked = this.btnLockConfiguration.IsChecked;
      int num3 = isChecked.Value ? 1 : 0;
      dictionary3.Add(configurationChecked, num3 != 0);
    }
    else
    {
      contorolsState.Add(CApRJRobotJogUtilities.LOCK_TCPF_CHECKED, false);
      contorolsState.Add(CApRJRobotJogUtilities.ENABLE_ROBOT_PLACEMENT_CHECKED, false);
      contorolsState.Add(CApRJRobotJogUtilities.ENABLE_ROBOT_ATTACHMENTS_PLACEMENT_SELECTED, false);
      contorolsState.Add(CApRJRobotJogUtilities.LOCK_CONFIGURATION_CHECKED, false);
    }
    CApRJRobotJogUtilities.StoreControlsStates((TxWindow) this, contorolsState);
    CApRJRobotJogUtilities.SetIntValueToRegistry((TxWindow) this, CApRJRobotJogUtilities.COPY_PARAMETERS, this.comboCopyParameters.SelectedIndex);
    CApRJRobotJogUtilities.SetIntValueToRegistry((TxWindow) this, CApRJRobotJogUtilities.COORDINATE_REFERENCE_LOCATION_RELATIVE, this.txCoordinateReference.comboBoxFrameOfReference.SelectedIndex);
  }

  private void LoadButtonsStates(Dictionary<string, bool> controlsState)
  {
    if (this.CompoundEquipment == null)
    {
      this.btnLockTCPF.IsChecked = new bool?(controlsState[CApRJRobotJogUtilities.LOCK_TCPF_CHECKED]);
      this.btnEnableRobotPlacement.IsChecked = new bool?(controlsState[CApRJRobotJogUtilities.ENABLE_ROBOT_PLACEMENT_CHECKED]);
      this.btnLockConfiguration.IsChecked = new bool?(controlsState[CApRJRobotJogUtilities.LOCK_CONFIGURATION_CHECKED]);
      this.btnEnableRobotPlacement.SelectedItem = !controlsState[CApRJRobotJogUtilities.ENABLE_ROBOT_ATTACHMENTS_PLACEMENT_SELECTED] ? 0 : 1;
    }
    this.txCoordinateReference.SnapToStepSize = controlsState[CApRJRobotJogUtilities.SNAP_BY_STEP_SIZE_CHECKED];
    this.btnShowDependentJoints.IsChecked = new bool?(controlsState[CApRJRobotJogUtilities.SHOW_DEPENDENT_JOINTS_CHECKED]);
  }

  private void LoadExpandersStates(Dictionary<string, bool> controlsState)
  {
    this.LocationNavigationExpander.IsExpanded = controlsState[CApRJRobotJogUtilities.LOCATION_EXPANDER_EXPANDED];
    this.ManipulationExpander.IsExpanded = controlsState[CApRJRobotJogUtilities.MANIPULATION_EXPANDER_EXPANDED];
    this.ExternalJointsExpander.IsExpanded = controlsState[CApRJRobotJogUtilities.EXTERNAL_JOINTS_EXPANDER_EXPANDED];
    if (this.AllJointsBlockExpander.IsEnabled)
      this.AllJointsBlockExpander.IsExpanded = controlsState[CApRJRobotJogUtilities.ALL_JOINTS_EXPANDER_EXPANDED];
    this.CoordinateReferenceBlock.IsExpanded = controlsState[CApRJRobotJogUtilities.COORDINATE_REFERENCE_EXPANDER_EXPANDED];
  }

  private void RegisterForDeleteObjects()
  {
    this.jointsBlock.RegisterForExternalAxisDeleted(new TxObject_DeletedEventHandler(this.Object_Deleted));
  }

  private void UnRegisterForDeleteObjects()
  {
    if (this._manipulationLogic == null)
      return;
    this.jointsBlock.UnRegisterForExternalAxisDeleted();
  }

  private void Object_Deleted(object sender, TxObject_DeletedEventArgs args)
  {
    ((Window) this).Close();
  }

  private void TxWindow_Loaded(object sender, RoutedEventArgs e)
  {
    Mouse.OverrideCursor = System.Windows.Input.Cursors.Wait;
    Mouse.UpdateCursor();
    TxApplicationEx.FreezeDisplay();
    (PresentationSource.FromVisual((Visual) this) as HwndSource).CompositionTarget.RenderMode = RenderMode.SoftwareOnly;
    this.InitFrameComboBox();
    this.SetTitle();
    object obj;
    TxWindowSettings.RestoreWindowValue((TxWindow) this, "ColumnsData", ref obj);
    this.jointsBlock.RawColumnData = obj as string;
    this._frameLogic = new CApRJRobotJogFrameLogic(this._manipulationLogic.Robot);
    this._jointJogLogic = new CApRJRobotJogJointsLogic((ITxDevice) this._manipulationLogic.Robot);
    this.txCoordinateReference.StepSizeChanged += new Action(this.StepSizeChanged);
    Dictionary<string, bool> controlsState = CApRJRobotJogUtilities.LoadControlsStates((TxWindow) this);
    if (this.CompoundEquipment == null)
    {
      this.LoadButtonsStates(controlsState);
    }
    else
    {
      this.LocationNavigationExpander.Visibility = Visibility.Collapsed;
      ((Window) this).SizeToContent = SizeToContent.Manual;
      ((Window) this).SizeToContent = SizeToContent.Height;
    }
    this.btnFollowMode.IsChecked = new bool?(this._manipulationLogic.Location != null);
    this.UpdateUIForCurrentRobot();
    this.RestoreFrameOfReference();
    if (this.CompoundEquipment == null)
      this.LoadExpandersStates(controlsState);
    bool isInitialLocationNotReached = this._initialLocation != null && this._manipulationLogic.Location != this._initialLocation;
    if (string.IsNullOrEmpty(((ContentControl) this.warningMessageBar).Content as string))
      this.NotifyLocationAndFollowModeState((ITxLocationOperation) this._initialLocation);
    this.DisableTcpfMovement();
    this.NotifyUnmovableTCPF();
    this.InitRobotList();
    this.SetExpandersInitialState(isInitialLocationNotReached);
    TxApplication.ActiveDocument.Unloading += new TxDocument_UnloadingEventHandler(this.ActiveDocument_Unloading);
    TxApplication.Options.Units.AngularUnitsChanged += new TxUnitsOptions_AngularUnitsChangedEventHandler(this.Units_AngularUnitsChanged);
    TxApplication.Options.Units.LinearUnitsChanged += new TxUnitsOptions_LinearUnitsChangedEventHandler(this.Units_LinearUnitsChanged);
    this.txCoordinateReference.comboBoxFrameOfReference.SelectedIndex = CApRJRobotJogUtilities.GetIntValueFromRegistry((TxWindow) this, CApRJRobotJogUtilities.COORDINATE_REFERENCE_LOCATION_RELATIVE, 2);
    TxApplicationEx.UnfreezeDisplay();
    TxApplication.RefreshDisplay();
    Mouse.OverrideCursor = (System.Windows.Input.Cursor) null;
    Mouse.UpdateCursor();
  }

  private void SetTitle()
  {
    if (this._manipulationLogic != null && TxRobot.op_Inequality(this._manipulationLogic.Robot, (ITxObject) null) && ((TxBaseGeometryCreationObject) this._manipulationLogic.Robot).Name != null)
    {
      // ISSUE: explicit non-virtual call
      __nonvirtual (((Window) this).Title) = $"{RJRobotJogResources.RobotJogWindowTitle}: {((TxBaseGeometryCreationObject) this._manipulationLogic.Robot).Name}";
    }
    else if (this.CompoundEquipment != null && ((ITxObject) this.CompoundEquipment).Name != null)
    {
      // ISSUE: explicit non-virtual call
      __nonvirtual (((Window) this).Title) = $"{RJRobotJogResources.RobotJogWindowTitle}: {((ITxObject) this.CompoundEquipment).Name}";
    }
    else
    {
      // ISSUE: explicit non-virtual call
      __nonvirtual (((Window) this).Title) = RJRobotJogResources.RobotJogWindowTitle;
    }
  }

  private void UpdateUIForCurrentRobot()
  {
    if (this._manipulationLogic.Clipboard.IsRobotPositionReadOnly && this._manipulationLogic.Clipboard.Equipment == null)
    {
      this.btnEnableRobotPlacement.IsChecked = new bool?(false);
      ((UIElement) this.btnEnableRobotPlacement).IsEnabled = false;
    }
    bool? isChecked;
    if (this.CompoundEquipment == null)
    {
      this._manipulationLogic.EnableRobotPlacement = this.btnEnableRobotPlacement.IsChecked.Value;
      this._manipulationLogic.MoveObjectsThatRobotIsAttachedTo = this.btnEnableRobotPlacement.SelectedItem == 1;
      CApRJRobotJogManipulationLogic manipulationLogic = this._manipulationLogic;
      isChecked = this.btnLockTCPF.IsChecked;
      int num = isChecked.Value ? 1 : 0;
      manipulationLogic.LockTCPF = num != 0;
    }
    CApRJRobotJogManipulationLogic manipulationLogic1 = this._manipulationLogic;
    isChecked = this.btnSetExternalAxes.IsChecked;
    int num1 = isChecked.Value ? 1 : 0;
    manipulationLogic1.SetRobotExternalAxisInLocation = num1 != 0;
    if (!this._manipulationLogic.IsConfigurationReady)
      this.btnLockConfiguration.IsChecked = new bool?(false);
    CApRJRobotJogManipulationLogic manipulationLogic2 = this._manipulationLogic;
    isChecked = this.btnLockConfiguration.IsChecked;
    int num2 = isChecked.Value ? 1 : 0;
    manipulationLogic2.IsConfigurationLocked = num2 != 0;
    this._manipulationLogic.IsFullyInitialized = true;
    this.RegisterForEvents();
    this.ddlConfiguration.DataContext = (object) this._manipulationLogic;
    this.jointsBlock.InitializeControl(this._jointJogLogic);
    this.RegisterJointLogicEvents();
    this._frameLogic.MovingObject = this._manipulationLogic.MovingObject;
    this.txCoordinateReference.RobotBase = this._manipulationLogic.Robot.Baseframe.AbsoluteLocation;
    this.txCoordinateReference.MovingObject = this._manipulationLogic.MovingObject;
    this.SetCorrdinatesReferenceNewReferenceFrame(this._frameLogic.FrameOfReference);
    this.FillFrameComboBox();
    ((FrameworkElement) this).MinHeight = ((FrameworkElement) this).ActualHeight;
    ((FrameworkElement) this).MaxHeight = ((FrameworkElement) this).ActualHeight;
    this._loadingWindow = false;
    CUiJointsControl jointsBlock = this.jointsBlock;
    isChecked = this.btnShowDependentJoints.IsChecked;
    int num3 = isChecked.Value ? 1 : 0;
    jointsBlock.ShowDependentJoints = num3 != 0;
    isChecked = this.btnShowDependentJoints.IsChecked;
    if (isChecked.Value)
      this.btnShowDependentJoints.ToolTip = (object) RJRobotJogResources.JointsOptions_HideDependentJoints;
    else
      this.btnShowDependentJoints.ToolTip = (object) RJRobotJogResources.JointsOptions_ShowDependentJoints;
    this.RegisterForDeleteObjects();
    this.jointsBlock.RegisterForExternalAxisesChange();
    this.StepSizeChanged();
  }

  private void RestoreFrameOfReference()
  {
    string frame_name = CApRJRobotJogUtilities.GetStringValueFromRegistry((TxWindow) this, CApRJRobotJogUtilities.FRAME_OF_REFERENCE, "");
    if (!TxFrame.op_Inequality(this._frameLogic.FrameOfReference, (ITxObject) null) || this._frameLogic.AllFrames.Where<TxFrame>((Func<TxFrame, bool>) (frame => frame.Name == frame_name)).Count<TxFrame>() <= 0)
      return;
    this._frameComboBoxCtrl.SelectFrame(frame_name);
  }

  private void StepSizeChanged()
  {
    this._manipulationLogic.TranslationStepSize = this.txCoordinateReference.TranslateStepValue;
    this._manipulationLogic.RotationStepSize = this.txCoordinateReference.RotateStepValue;
    this._manipulationLogic.SnapToStepSize = this.txCoordinateReference.SnapToStepSize;
  }

  protected virtual void OnClosed(EventArgs e)
  {
    TxApplicationEx.FreezeDisplay();
    try
    {
      bool? isChecked = this.btnTeachLocation.IsChecked;
      bool flag = true;
      if (isChecked.GetValueOrDefault() == flag & isChecked.HasValue)
        this.TeachOneLocation();
      this.btnFollowMode.IsChecked = new bool?(false);
      this.txLocationNavigationControl.UnInitialize();
      this.UnregisterJointLogicEvents();
      if (!this._wasForcedToClose)
      {
        TxApplication.ActiveDocument.Unloading -= new TxDocument_UnloadingEventHandler(this.ActiveDocument_Unloading);
        TxApplication.Options.Units.AngularUnitsChanged -= new TxUnitsOptions_AngularUnitsChangedEventHandler(this.Units_AngularUnitsChanged);
        TxApplication.Options.Units.LinearUnitsChanged -= new TxUnitsOptions_LinearUnitsChangedEventHandler(this.Units_LinearUnitsChanged);
        this.UnRegisterForDeleteObjects();
        this.jointsBlock.UnRegisterForExternalAxisesChange();
        this.jointsBlock.UnInitializeControl();
        this.txCoordinateReference.MovingObject = (ITxLocatableObject) null;
        if (this.CompoundEquipment == null)
        {
          if (this._frameLogic != null)
          {
            this.StoreFrameOfReference();
            this._frameLogic.Delete();
          }
          this.StoreCotrolsStates();
        }
        else
        {
          this.StoreRobotInfo();
          this._robotsManager.DeleteAllTemporaryFrames();
        }
      }
      if (this._manipulationLogic != null)
      {
        this._restoreOriginalValues = false;
        while (this._manipulationLogic.IsInDisableTCPTrackingMode)
          this._manipulationLogic.EndDisableTCPTrackingMode();
        this._manipulationLogic.Terminate();
        this.UnRegisterManipulationLogicEvents();
        this._manipulationLogic = (CApRJRobotJogManipulationLogic) null;
      }
      this.txManManipulationControl.UnInitialize();
      if (this.CompoundEquipment != null)
        this._robotsManager.Clear();
      this._gunDisplayer.Hide();
    }
    finally
    {
      base.OnClosed(e);
      TxApplicationEx.UnfreezeDisplay();
      TxApplication.RefreshDisplay();
    }
  }

  private void StoreFrameOfReference()
  {
    string name = TxFrame.op_Inequality(this._frameLogic.FrameOfReference, (ITxObject) null) ? this._frameLogic.FrameOfReference.Name : "";
    CApRJRobotJogUtilities.SetStringValueToRegistry((TxWindow) this, CApRJRobotJogUtilities.FRAME_OF_REFERENCE, name);
  }

  private void Exit() => this._wasForcedToClose = true;

  private void TxWindow_PreviewMouseDown(object sender, MouseButtonEventArgs e)
  {
    if (e.Source == this._frameComboBoxCtrl)
      return;
    this._frameComboBoxCtrl.LoseFocus();
  }

  private void ExpanderBlock_SizeChanged(object sender, SizeChangedEventArgs e)
  {
    if (this._loadingWindow)
      return;
    double num = ((FrameworkElement) this).ActualHeight + (e.NewSize.Height - e.PreviousSize.Height);
    ((FrameworkElement) this).MinHeight = num;
    ((FrameworkElement) this).MaxHeight = num;
  }

  private void ActiveDocument_Unloading(object sender, TxDocument_UnloadingEventArgs args)
  {
    ((Window) this).Close();
  }

  private void FrameComboBoxCtrl_LostFocus(object sender, EventArgs e)
  {
    if (this._frameLogic.IsFrameOfReferenceValid || this._frameLogic.MovingObject == null)
      return;
    this._frameComboBoxCtrl.SelectFrame(this._frameLogic.FrameOfReference.Name);
    ((System.Windows.Forms.Control) this._frameComboBoxCtrl).Text = this._frameLogic.FrameOfReference.Name;
  }

  private void RegisterForEvents()
  {
    this._manipulationLogic.PropertyChanged += (PropertyChangedEventHandler) ((x, y) =>
    {
      switch (y.PropertyName)
      {
        case "MovingObject":
          this._frameLogic.MovingObject = this._manipulationLogic.MovingObject;
          this.FillFrameComboBox();
          this.txCoordinateReference.MovingObject = this._manipulationLogic.MovingObject;
          break;
        case "ConfigurationChangedFromOutsideRJ":
          this.RobotConfigurationChangedFromOutside();
          break;
        case "FollowModeExitedFromOutsideRJ":
          this.FollowModeToggledOffFRomOutside();
          break;
        case "AbsoluteLocationChanged":
          this._frameLogic.AbsoluteLocationChanged();
          this.txCoordinateReference.MovingObjectAbsoluteLocationChanged();
          break;
        case "Location":
          this.SetLocation();
          break;
        case "IsTcpfMovable":
          this.DisableTcpfMovement();
          this.NotifyUnmovableTCPF();
          break;
      }
    });
    this._frameLogic.FrameOfReferenceChanged += (Action<TxFrame>) (x =>
    {
      this._manipulationLogic.FrameOfReferenceChanged(x);
      this.txCoordinateReference.RobotBase = this._manipulationLogic.Robot.Baseframe.AbsoluteLocation;
      this.SetCorrdinatesReferenceNewReferenceFrame(x);
    });
    this._frameLogic.FrameOfReferenceLocationChanged += (Action<TxFrame>) (x =>
    {
      this._manipulationLogic.FrameOfReferenceLocationChanged(x);
      this.txCoordinateReference.RobotBase = this._manipulationLogic.Robot.Baseframe.AbsoluteLocation;
      this.SetCorrdinatesReferenceNewReferenceFrame(x);
    });
    this._frameLogic.FramesUpdated += (Action) (() => this.FillFrameComboBox(true));
  }

  private void SetCorrdinatesReferenceNewReferenceFrame(TxFrame x)
  {
    this.txCoordinateReference.FrameType = this._frameLogic.FrameType;
    this.txCoordinateReference.ReferenceFrame = TxFrame.op_Inequality(x, (ITxObject) null) ? x.AbsoluteLocation : (TxTransformation) null;
  }

  private void SetLocation()
  {
    if (this._manipulationLogic.Location != null)
    {
      bool? isChecked = this.btnFollowMode.IsChecked;
      bool flag = true;
      if (isChecked.GetValueOrDefault() == flag & isChecked.HasValue)
      {
        this.txLocationNavigationControl.Location = (ITxLocationOperation) this._manipulationLogic.Location;
        this._jointJogLogic.SavePose();
        goto label_5;
      }
    }
    if (!this._isTeachLocationClicked && this.txLocationNavigationControl.Location != null)
      this.btnFollowMode.IsChecked = new bool?(false);
label_5:
    this.SetTitle();
  }

  private void DisableTcpfMovement()
  {
    bool? nullable;
    if (this._manipulationLogic.IsTcpfMovable)
    {
      if (this._savedLockTCPF.HasValue)
      {
        this.btnLockTCPF.IsEnabled = true;
        bool? isChecked = this.btnLockTCPF.IsChecked;
        nullable = this._savedLockTCPF;
        if (!(isChecked.GetValueOrDefault() == nullable.GetValueOrDefault() & isChecked.HasValue == nullable.HasValue))
        {
          this.btnLockTCPF.IsChecked = this._savedLockTCPF;
          CApRJRobotJogManipulationLogic manipulationLogic = this._manipulationLogic;
          nullable = this.btnLockTCPF.IsChecked;
          int num = nullable.Value ? 1 : 0;
          manipulationLogic.LockTCPF = num != 0;
          this.SetExpandersState();
        }
        this._savedLockTCPF = new bool?();
      }
    }
    else if (!this._savedLockTCPF.HasValue)
    {
      this._savedLockTCPF = this.btnLockTCPF.IsChecked;
      this.btnLockTCPF.IsEnabled = false;
      if (!this.btnLockTCPF.IsChecked.Value)
      {
        this.btnLockTCPF.IsChecked = new bool?(true);
        CApRJRobotJogManipulationLogic manipulationLogic = this._manipulationLogic;
        nullable = this.btnLockTCPF.IsChecked;
        int num = nullable.Value ? 1 : 0;
        manipulationLogic.LockTCPF = num != 0;
        this.SetExpandersState();
      }
    }
    TxToolbarSplitButton enableRobotPlacement = this.btnEnableRobotPlacement;
    nullable = this.btnLockTCPF.IsChecked;
    int num1 = nullable.Value ? 1 : 0;
    ((UIElement) enableRobotPlacement).IsEnabled = num1 != 0;
  }

  private void Units_AngularUnitsChanged(
    object sender,
    TxUnitsOptions_AngularUnitsChangedEventArgs args)
  {
    this.jointsBlock.RefreshJoints();
    this.RefreshJointsExpanders();
  }

  private void Units_LinearUnitsChanged(
    object sender,
    TxUnitsOptions_LinearUnitsChangedEventArgs args)
  {
    this.jointsBlock.RefreshJoints();
    this.RefreshJointsExpanders();
  }

  private void _jointJogLogic_LimitsControlsEntered(object sender, EventArgs args)
  {
    this.btnResetToHardLimits.IsEnabled = true;
    this.btnResetToHardLimits.Tag = sender;
  }

  private void _jointJogLogic_LimitsControlsLeaved(object sender, EventArgs args)
  {
    this.btnResetToHardLimits.IsEnabled = false;
    this.btnResetToHardLimits.Tag = (object) null;
  }

  private void frameComboBoxCtrl_InvalidFrameSet(
    object sender,
    TxFrameComboBoxCtrl_InvalidFrameSetEventArgs args)
  {
    this._frameLogic.IsFrameOfReferenceValid = false;
  }

  private void frameComboBoxCtrl_ValidFrameSet(
    object sender,
    TxFrameComboBoxCtrl_ValidFrameSetEventArgs args)
  {
    this._frameLogic.FrameChanged(((System.Windows.Forms.Control) this._frameComboBoxCtrl).Text, args.Location);
  }

  public void UpdateManipulatorControl(TxTransformation delta)
  {
    if (!this._manipulationLogic.Manipulate(delta))
      return;
    this._notifyFromManipulator = true;
    this.txManManipulationControl.Manipulate(delta);
    this._notifyFromManipulator = false;
  }

  private bool txCoordinateReference_DeltaChanged(
    object sender,
    CUiCoordinateReferenceDeltaChangedEventArgs args)
  {
    this.ResetManipulation();
    return this._manipulationLogic.Manipulate(args.Delta, args.ReferenceFrame);
  }

  private void txManManipulationControl_DeltaChanged(
    object sender,
    TxPlacementCollisionControlDeltaChangedEventArgs args)
  {
    TxPerformanceMeasurementEx.StartMeasureTask("RobotJog Shift");
    this._manipulationLogic.UpdateManipulatorSelectedAxis(this.txManManipulationControl.SelectedAxis);
    args.ObjectMoved = this._manipulationLogic.Manipulate(args.Delta);
    TxPerformanceMeasurementEx.StopMeasureTask("RobotJog Shift");
  }

  public void txManManipulationControl_RunToCollision(
    object sender,
    TxPlacementCollisionControlRunCollisionEventArgs args)
  {
    if (this._manipulationLogic == null)
      return;
    if (args.StartOrStopCollision == 1)
    {
      this.RuntToCollision(sender, args);
    }
    else
    {
      if (args.StartOrStopCollision != 2)
        return;
      this.StopRuntToCollision();
    }
  }

  private void RuntToCollision(
    object sender,
    TxPlacementCollisionControlRunCollisionEventArgs args)
  {
    this.btnReset.IsEnabled = false;
    this._restoreOriginalValues = true;
    double num1 = 0.0;
    if (args.MoveOrRotateRunCollision == 1)
      num1 = this.txManManipulationControl.LinearValue;
    else if (args.MoveOrRotateRunCollision == 2)
      num1 = this.txManManipulationControl.AngularValue;
    TxApplication.ActiveUndoManager.StartTransaction();
    bool disableTcpTrackingMode = this._manipulationLogic.ShouldDisableTCPTrackingMode;
    try
    {
      if (disableTcpTrackingMode)
        this._manipulationLogic.BeginDisableTCPTrackingMode();
      bool collision = this._manipulationLogic.RunToCollision(args);
      this._manipulationLogic.UpdateManipulatorSelectedAxis(this.txManManipulationControl.SelectedAxis);
      if (!collision)
      {
        if (this._restoreOriginalValues)
        {
          if (this._manipulationLogic != null)
          {
            if (sender != null)
            {
              int num2 = (int) CApRJRobotJogNotificationService.NotifyModal(RJRobotJogResources.CollisionReportMessage, RJRobotJogResources.CollisionReportTitle, MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
            }
            this._restoreOriginalValues = false;
            this._manipulationLogic.RestoreRobotToPoseBeforeCollisionRun();
            if (args.MoveOrRotateRunCollision == 1)
              this.txManManipulationControl.LinearValue = num1;
            else if (args.MoveOrRotateRunCollision == 2)
              this.txManManipulationControl.AngularValue = num1;
          }
        }
      }
    }
    catch (TxException ex)
    {
    }
    finally
    {
      if (disableTcpTrackingMode && this._manipulationLogic != null)
        this._manipulationLogic.EndDisableTCPTrackingMode();
      TxApplication.ActiveUndoManager.EndTransaction();
      TxApplication.RefreshDisplay();
    }
    this.btnReset.IsEnabled = true;
  }

  private void StopRuntToCollision()
  {
    this._restoreOriginalValues = false;
    this._manipulationLogic.StopRunToCollision();
  }

  private void txManManipulationControl_MovementTypeChanged(
    object sender,
    TxPlacementCollisionControlMovementTypeChangedEventArgs args)
  {
    MovementAxis axis = MovementAxis.None;
    switch (args.MovementType - 4)
    {
      case 0:
        axis = MovementAxis.Rx;
        break;
      case 1:
        axis = MovementAxis.Ry;
        break;
      case 2:
        axis = MovementAxis.Rz;
        break;
    }
    this._manipulationLogic.ShowCircle(axis);
    if (!this._notifyFromManipulator)
      this._manipulationLogic.UpdateManipulatorSelectedAxis(args.MovementType);
    TxApplication.RefreshDisplay();
  }

  private void ddlConfiguration_DropDownOpened(object sender, EventArgs e)
  {
    this._manipulationLogic.FillRobotConfigurationList();
  }

  private void LocationNavigationExpander_Collapsed(object sender, RoutedEventArgs args)
  {
    this.NotifyClear();
  }

  private void JointsExpanderHasExpanded(object sender, RoutedEventArgs args)
  {
    Expander expander = sender as Expander;
    if (expander == this.AllJointsBlockExpander)
    {
      this.ExternalJointsExpander.IsExpanded = false;
      this.jointsBlock.Layout = JointsLayout.AllJoints;
      this.ExternalJointsExpander.Content = (object) null;
      this.AllJointsBlockExpander.Content = (object) this.jointsBlock;
    }
    else if (expander == this.ExternalJointsExpander)
    {
      this.AllJointsBlockExpander.IsExpanded = false;
      this.jointsBlock.Layout = JointsLayout.ExternalJoints;
      this.AllJointsBlockExpander.Content = (object) null;
      this.ExternalJointsExpander.Content = (object) this.jointsBlock;
    }
    this.UpdateMasterSlaveModeIsTakingInAccountFlag();
    this.RefreshUI();
  }

  private void RobotConfigurationChangedFromOutside()
  {
    if (CApRJRobotJogNotificationService.IsTesting)
    {
      int num1 = (int) CApRJRobotJogNotificationService.Notify(RJRobotJogResources.RobotConfigurationChangedFromOutside, RJRobotJogResources.RobotJogName, MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
    }
    else
    {
      int num2 = (int) System.Windows.Forms.MessageBox.Show(RJRobotJogResources.RobotConfigurationChangedFromOutside, RJRobotJogResources.RobotJogName, MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
    }
    this.btnLockConfiguration.IsChecked = new bool?(this._manipulationLogic.IsConfigurationLocked);
  }

  private void FollowModeToggledOffFRomOutside()
  {
    if (!this.LocationNavigationExpander.IsExpanded)
      this.LocationNavigationExpander.IsExpanded = true;
    this.Notify(RJRobotJogResources.FollowModeToggledOffFRomOutside);
  }

  private void CurrentRobot_SelectionChanged(object sender, EventArgs e)
  {
    Mouse.OverrideCursor = System.Windows.Input.Cursors.Wait;
    Mouse.UpdateCursor();
    this.txCoordinateReference._isInFreeze = true;
    int selectedIndex = this.txCoordinateReference.comboBoxFrameOfReference.SelectedIndex;
    TxRobot txRobot = this.currentRobot.Object as TxRobot;
    if (this._manipulationLogic != null && TxRobot.op_Inequality(txRobot, (ITxObject) this._manipulationLogic.Robot))
    {
      this.StoreRobotInfo();
      this._restoreOriginalValues = false;
      this.UnregisterJointLogicEvents();
      this._manipulationLogic.Terminate();
      this.UnRegisterManipulationLogicEvents();
      this._manipulationLogic = (CApRJRobotJogManipulationLogic) null;
      if (TxRobot.op_Inequality(txRobot, (ITxObject) null))
      {
        this._dontStoreRobotInfo = true;
        this._manipulationLogic = new CApRJRobotJogManipulationLogic((ITxObject) txRobot, new UpdateDelta(this.UpdateManipulatorControl), new DnProcessSimulateCommands.RobotJog.ResetManipulatorControl(this.ResetManipulatorControl), new ForceExit(this.Exit), new TxObject_DeletedEventHandler(this.Object_Deleted));
        this.RegisterManipulationLogicEvents();
        this.ReStoreRobotInfo(txRobot);
        this.UpdateUIForCurrentRobot();
        this.jointsBlock.RefreshJoints();
        this.RefreshJointsExpanders();
      }
    }
    this._manipulationLogic._isFreezed = true;
    this.txManManipulationControl.LinearValue = 0.0;
    this.txManManipulationControl.AngularValue = 0.0;
    this.UpdateMasterSlaveModeIsTakingInAccountFlag();
    this.RefreshUI();
    this._manipulationLogic._isFreezed = false;
    if (this._isMasterSlaveModeIsNotTakingInAccount)
      this.ReStoreFramesFromRobotInfo(txRobot);
    this._manipulationLogic.ReferenceFrame = this._manipulationLogic.ReferenceFrame;
    this.txCoordinateReference._isInFreeze = false;
    this.txCoordinateReference.comboBoxFrameOfReference.SelectedIndex = selectedIndex;
    this.txCoordinateReference.MovingObjectAbsoluteLocationChanged();
    this._dontStoreRobotInfo = false;
    TxApplication.RefreshDisplay();
    Mouse.OverrideCursor = (System.Windows.Input.Cursor) null;
    Mouse.UpdateCursor();
  }

  private void RegisterManipulationLogicEvents()
  {
    if (this._manipulationLogic == null)
      return;
    this._manipulationLogic.ManipulatorAxisChanged += new EventHandler<PlacementSelectedAxisChangedEventArgs>(this._manipulationLogic_ManipulatorAxisChanged);
  }

  private void UnRegisterManipulationLogicEvents()
  {
    if (this._manipulationLogic == null)
      return;
    this._manipulationLogic.ManipulatorAxisChanged -= new EventHandler<PlacementSelectedAxisChangedEventArgs>(this._manipulationLogic_ManipulatorAxisChanged);
  }

  private void _manipulationLogic_ManipulatorAxisChanged(
    object sender,
    PlacementSelectedAxisChangedEventArgs e)
  {
    this.UpdateManipulationControlSelectedAxis(e.SelectedAxes);
  }

  private void RefreshJointsExpanders()
  {
    if (this.AllJointsBlockExpander.IsExpanded)
    {
      this.ExternalJointsExpander.IsExpanded = false;
      this.jointsBlock.Layout = JointsLayout.AllJoints;
      this.ExternalJointsExpander.Content = (object) null;
      this.AllJointsBlockExpander.Content = (object) this.jointsBlock;
    }
    else
    {
      if (!this.ExternalJointsExpander.IsExpanded)
        return;
      this.AllJointsBlockExpander.IsExpanded = false;
      this.jointsBlock.Layout = JointsLayout.ExternalJoints;
      this.AllJointsBlockExpander.Content = (object) null;
      this.ExternalJointsExpander.Content = (object) this.jointsBlock;
    }
  }

  private void ReStoreRobotInfo(TxRobot robot)
  {
    CApRJSingleRobotInfo robotInfo = this._robotsManager.GetRobotInfo(robot);
    if (robotInfo != null)
    {
      this.btnLockTCPF.IsChecked = new bool?(robotInfo.IsLockedTCPF);
      this.btnEnableRobotPlacement.IsChecked = new bool?(robotInfo.IsEnabledRobotPlacement);
      this.btnEnableRobotPlacement.SelectedItem = robotInfo.EnableRobotPlacementMode;
      this.btnLockConfiguration.IsChecked = new bool?(robotInfo.IsLockConfiguration);
      this._frameLogic = robotInfo.Framelogic;
      this._jointJogLogic = robotInfo.JogJointsLogic;
      this.txCoordinateReference.OriginalFrame = robotInfo.OriginalFrame;
      this.ddRobotMasterSlaveRole.SelectedItem = (object) this.GetRobotMasterSlaveRoleStr(robotInfo.MasterSlaveRole);
    }
    else
    {
      this.btnLockTCPF.IsChecked = new bool?(false);
      this.btnEnableRobotPlacement.IsChecked = new bool?(false);
      this.btnEnableRobotPlacement.SelectedItem = 0;
      this.btnLockConfiguration.IsChecked = new bool?(false);
      this._frameLogic = new CApRJRobotJogFrameLogic(this._manipulationLogic.Robot);
      this.ddRobotMasterSlaveRole.SelectedItem = (object) this._robotRoleOptionNone;
    }
  }

  private RobotMasterSlaveRole GetRobotMasterSlaveRole(string roleStr)
  {
    RobotMasterSlaveRole robotMasterSlaveRole = RobotMasterSlaveRole.NONE;
    if (roleStr == this._robotRoleOptionMaster)
      robotMasterSlaveRole = RobotMasterSlaveRole.MASTER;
    else if (roleStr == this._robotRoleOptionSlave)
      robotMasterSlaveRole = RobotMasterSlaveRole.SLAVE;
    return robotMasterSlaveRole;
  }

  private string GetRobotMasterSlaveRoleStr(RobotMasterSlaveRole role)
  {
    string masterSlaveRoleStr = this._robotRoleOptionNone;
    switch (role)
    {
      case RobotMasterSlaveRole.SLAVE:
        masterSlaveRoleStr = this._robotRoleOptionSlave;
        break;
      case RobotMasterSlaveRole.MASTER:
        masterSlaveRoleStr = this._robotRoleOptionMaster;
        break;
    }
    return masterSlaveRoleStr;
  }

  private void ReStoreFramesFromRobotInfo(TxRobot robot)
  {
    this._manipulationLogic._isFreezed = false;
    this._manipulationLogic.IsFullyInitialized = true;
    CApRJSingleRobotInfo robotInfo = this._robotsManager.GetRobotInfo(robot);
    if (robotInfo == null)
      return;
    this.txCoordinateReference.OriginalFrame = robotInfo.OriginalFrame;
    if (robotInfo.FrameOfRefernceText == RJRobotJogResources.WorkingFrame || robotInfo.FrameOfRefernceText == "TCPF" || robotInfo.FrameOfRefernceText == "BASEFRAME")
      this._frameComboBoxCtrl.SelectFrame(robotInfo.FrameOfRefernceText);
    else if (robotInfo.FrameOfRefernceText != "")
    {
      this._frameComboBoxCtrl.RemoveFrame(robotInfo.FrameOfRefernceText);
      if (TxTransformation.op_Inequality(robotInfo.FrameOfRefernceTransformation, (TxTransformation) null))
        this._frameComboBoxCtrl.SetCurrentFrame(robotInfo.FrameOfRefernceText, robotInfo.FrameOfRefernceTransformation);
      else
        this._frameComboBoxCtrl.SelectFrame("TCPF");
    }
    else
      this._frameComboBoxCtrl.SelectFrame("TCPF");
  }

  private void StoreRobotInfo()
  {
    if (this._isMasterSlaveModeIsNotTakingInAccount && !this._dontStoreRobotInfo)
    {
      CApRJSingleRobotInfo currentRobotInfo = new CApRJSingleRobotInfo();
      bool? isChecked = this.btnLockTCPF.IsChecked;
      currentRobotInfo.IsLockedTCPF = isChecked.Value;
      isChecked = this.btnEnableRobotPlacement.IsChecked;
      currentRobotInfo.IsEnabledRobotPlacement = isChecked.Value;
      currentRobotInfo.EnableRobotPlacementMode = this.btnEnableRobotPlacement.SelectedItem;
      isChecked = this.btnLockConfiguration.IsChecked;
      currentRobotInfo.IsLockConfiguration = isChecked.Value;
      currentRobotInfo.Framelogic = this._frameLogic;
      currentRobotInfo.OriginalFrame = this.txCoordinateReference.OriginalFrame;
      currentRobotInfo.MasterSlaveRole = this.GetRobotMasterSlaveRole((string) this.ddRobotMasterSlaveRole.SelectedItem);
      currentRobotInfo.FrameOfRefernceText = ((System.Windows.Forms.Control) this._frameComboBoxCtrl).Text;
      currentRobotInfo.FrameOfRefernceTransformation = this._frameComboBoxCtrl.GetLocation();
      this._robotsManager.UpdateRobotInfo(this._manipulationLogic.Robot, currentRobotInfo);
    }
    else
      this._robotsManager.UpdateRobotInfoLockConfiguration(this._manipulationLogic.Robot, this.btnLockConfiguration.IsChecked.Value);
  }

  private void StoreFirstTimeRobotInfo(TxRobot robot)
  {
    CApRJSingleRobotInfo currentRobotInfo = new CApRJSingleRobotInfo()
    {
      Framelogic = new CApRJRobotJogFrameLogic(robot),
      OriginalFrame = robot.TCPF.AbsoluteLocation,
      JogJointsLogic = new CApRJRobotJogJointsLogic((ITxDevice) robot),
      IsRobotPositionReadOnly = TxComponentEx.IsScopeReadOnly((ITxObject) robot)
    };
    currentRobotInfo.OriginalRobotLocation = currentRobotInfo.IsRobotPositionReadOnly ? (this.CompoundEquipment as ITxLocatableObject).AbsoluteLocation : robot.AbsoluteLocation;
    this._robotsManager.AddRobotInfo(robot, currentRobotInfo);
  }

  private void _jointJogLogic_BeforeJointValueChange(TxJoint joint)
  {
    if (this._manipulationLogic.ShouldDisableTCPTrackingMode)
    {
      if (this._disableTCPTrackingOnBeforeJointValueChange == 0)
        this._manipulationLogic.BeginDisableTCPTrackingMode();
      ++this._disableTCPTrackingOnBeforeJointValueChange;
    }
    this.ResetManipulation();
  }

  private void ResetManipulation()
  {
    this._manipulationLogic.UpdateManipulatorSelectedAxis((Axes) 0);
    this.ResetManipulatorControl();
    this.UpdateManipulationControlSelectedAxis((Axes) 0);
  }

  private void UpdateManipulationControlSelectedAxis(Axes axes)
  {
    if (!((UIElement) this.txManManipulationControl).IsEnabled || this.txManManipulationControl.SelectedAxis == axes)
      return;
    this._notifyFromManipulator = true;
    this.txManManipulationControl.SelectedAxis = axes;
    this._notifyFromManipulator = false;
  }

  private void _jointJogLogic_AfterJointValueChange(TxJoint joint)
  {
    if (this._disableTCPTrackingOnBeforeJointValueChange <= 0)
      return;
    --this._disableTCPTrackingOnBeforeJointValueChange;
    if (this._disableTCPTrackingOnBeforeJointValueChange != 0)
      return;
    this._manipulationLogic.EndDisableTCPTrackingMode();
  }

  public void btnClose_Click(object sender, RoutedEventArgs e) => ((Window) this).Close();

  public void btnReset_Click(object sender, RoutedEventArgs e)
  {
    this._manipulationLogic.BeginDisableTCPTrackingMode();
    this.ResetManipulatorControl();
    if (this.CompoundEquipment != null)
    {
      this._manipulationLogic.HideCircle();
      if (this._robotsManager.GetRobotMasterSlaveMode())
        this._robotsManager.RemoveMasterSlaveBehavior();
      foreach (TxRobot key in this._robotsManager.RobotsInfo.Keys)
      {
        CApRJSingleRobotInfo rjSingleRobotInfo = this._robotsManager.RobotsInfo[key];
        rjSingleRobotInfo.JogJointsLogic.Reset();
        if (!rjSingleRobotInfo.IsRobotPositionReadOnly)
          key.AbsoluteLocation = rjSingleRobotInfo.OriginalRobotLocation;
        else
          (this.CompoundEquipment as ITxLocatableObject).AbsoluteLocation = rjSingleRobotInfo.OriginalRobotLocation;
      }
      if (this._robotsManager.GetRobotMasterSlaveMode())
        this._robotsManager.CreateMasterSlaveBehavior();
      this._manipulationLogic.FillRobotConfigurationList();
      TxGraphicViewerEx.RequireRefreshSynchronization();
      TxApplication.RefreshDisplay();
    }
    else
    {
      this._jointJogLogic.Reset();
      this._manipulationLogic.Reset();
    }
    this._manipulationLogic.EndDisableTCPTrackingMode();
  }

  private void ResetManipulatorControl() => this.txManManipulationControl.Reset();

  public void btnLockConfiguration_Click(object sender, RoutedEventArgs e)
  {
    this._manipulationLogic.IsConfigurationLocked = this.btnLockConfiguration.IsChecked.Value;
    if (this.btnLockConfiguration.IsChecked.Value)
      this.Notify(RJRobotJogResources.NotifyConfigurationLocked);
    else
      this.Notify(RJRobotJogResources.NotifyConfigurationUnlocked);
    bool? isChecked = this.btnTeachLocation.IsChecked;
    bool flag = true;
    if (!(isChecked.GetValueOrDefault() == flag & isChecked.HasValue))
      return;
    this.TeachOneLocation();
  }

  private void FillFrameComboBox(bool forceUpdate = false)
  {
    if (!forceUpdate && this._frameComboBoxMovingObjId != null && this._frameLogic.MovingObject != null && ((ITxObject) this._frameLogic.MovingObject).Id == this._frameComboBoxMovingObjId && TxFrame.op_Inequality(this._frameLogic.FrameOfReference, (ITxObject) null) && this._frameLogic.FrameOfReference.Name == ((System.Windows.Forms.Control) this._frameComboBoxCtrl).Text && TxTransformation.op_Equality(this._frameLogic.FrameOfReference.AbsoluteLocation, this._frameComboBoxCtrl.GetLocation()))
      return;
    this._frameComboBoxCtrl.Clear();
    if (this._frameLogic.MovingObject != null)
    {
      this._frameComboBoxMovingObjId = ((ITxObject) this._frameLogic.MovingObject).Id;
      foreach (TxFrame allFrame in this._frameLogic.AllFrames)
        this._frameComboBoxCtrl.AddFrame(allFrame);
      this._frameComboBoxCtrl.SelectFrame(this._frameLogic.FrameOfReference.Name);
    }
    else
      this._frameComboBoxMovingObjId = (string) null;
  }

  private void btnMasterSlaveMode_Click(object sender, RoutedEventArgs e)
  {
    if (this._robotsManager != null)
      this._robotsManager.SetMasterSlaveMode(this.btnMasterSlaveMode.IsChecked.Value);
    this.UpdateMasterSlaveModeIsTakingInAccountFlag();
    this.RefreshUI();
  }

  private void ddRobotMasterSlaveRole_SelectionChanged(object sender, SelectionChangedEventArgs e)
  {
    if (this.currentRobot != null && this.currentRobot.Object != null)
    {
      if (this._robotsManager.GetRobotInfo(this.currentRobot.Object as TxRobot) == null)
        this.StoreRobotInfo();
      RobotMasterSlaveRole robotMasterSlaveRole = this.GetRobotMasterSlaveRole((string) this.ddRobotMasterSlaveRole.SelectedItem);
      if (this._robotsManager.CanSetRobotRole(this.currentRobot.Object, robotMasterSlaveRole))
      {
        this._robotsManager.SetRobotsRole(this.currentRobot.Object, robotMasterSlaveRole);
      }
      else
      {
        if (RobotMasterSlaveRole.MASTER == robotMasterSlaveRole)
        {
          int num1 = (int) CApRJRobotJogNotificationService.Notify(RJRobotJogResources.MasterRoleAssignmentFailedMessage, RJRobotJogResources.MasterSlaveRoleAssignmentTitle, MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
        }
        else if (RobotMasterSlaveRole.SLAVE == robotMasterSlaveRole)
        {
          int num2 = (int) CApRJRobotJogNotificationService.Notify(RJRobotJogResources.SlaveRoleAssignmentFailedMessage, RJRobotJogResources.MasterSlaveRoleAssignmentTitle, MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
        }
        this.ddRobotMasterSlaveRole.SelectedItem = e.RemovedItems[0];
      }
    }
    this.UpdateMasterSlaveModeIsTakingInAccountFlag();
    this.RefreshUI();
  }

  private void UpdateMasterSlaveModeIsTakingInAccountFlag()
  {
    this._isMasterSlaveModeIsNotTakingInAccount = true;
    if (this.ddRobotMasterSlaveRole.SelectedItem == null || this.GetRobotMasterSlaveRole(this.ddRobotMasterSlaveRole.SelectedItem.ToString()) != RobotMasterSlaveRole.SLAVE || this._robotsManager == null || !this._robotsManager.GetRobotMasterSlaveMode() || !this._robotsManager.IsMasterExist())
      return;
    this._isMasterSlaveModeIsNotTakingInAccount = false;
  }

  private void btnEnableRobotPlacement_Clicked()
  {
    if (this._manipulationLogic.MoveObjectsThatRobotIsAttachedTo == (this.btnEnableRobotPlacement.SelectedItem == 1))
      return;
    this._manipulationLogic.MoveObjectsThatRobotIsAttachedTo = this.btnEnableRobotPlacement.SelectedItem == 1;
    this.Notify(RJRobotJogResources.NotifyRobotPlacementON);
  }

  private void btnEnableRobotPlacementAndAttachments_Clicked()
  {
    if (this._manipulationLogic.MoveObjectsThatRobotIsAttachedTo == (this.btnEnableRobotPlacement.SelectedItem == 1))
      return;
    this._manipulationLogic.MoveObjectsThatRobotIsAttachedTo = this.btnEnableRobotPlacement.SelectedItem == 1;
    this.Notify(RJRobotJogResources.NotifyRobotPlacementWithAttachmentsON);
  }

  private void RefreshUI()
  {
    if (this.CompoundEquipment != null)
      this.RefreshUiForCompoundEquipment();
    else
      this.RefreshUiForRobot();
  }

  private void RefreshUiForCompoundEquipment()
  {
    if (this.btnLockTCPF.IsEnabled && !this._isMasterSlaveModeIsNotTakingInAccount && !this._dontStoreRobotInfo)
    {
      this._robotsManager.UpdateRobotInfo(this._manipulationLogic.Robot, new CApRJFrameOfRefernceInfo()
      {
        FrameOfRefernceText = ((System.Windows.Forms.Control) this._frameComboBoxCtrl).Text,
        FrameOfRefernceTransformation = this._frameComboBoxCtrl.GetLocation()
      });
      this._robotsManager.ComboBoxFrameOfReferenceSelectedIndex = this.txCoordinateReference.comboBoxFrameOfReference.SelectedIndex;
    }
    bool flag1 = !this.btnLockTCPF.IsEnabled && this._isMasterSlaveModeIsNotTakingInAccount;
    this.jointsBlock.IsEnabled = this._isMasterSlaveModeIsNotTakingInAccount && this.jointsBlock.JointsCount > 0;
    this.btnLockTCPF.IsEnabled = this._isMasterSlaveModeIsNotTakingInAccount;
    ((UIElement) this.btnEnableRobotPlacement).IsEnabled = this._isMasterSlaveModeIsNotTakingInAccount && this.btnLockTCPF.IsChecked.Value;
    bool? isChecked;
    int num1;
    if (this._isMasterSlaveModeIsNotTakingInAccount)
    {
      isChecked = this.btnLockTCPF.IsChecked;
      bool flag2 = false;
      if (isChecked.GetValueOrDefault() == flag2 & isChecked.HasValue)
      {
        num1 = 1;
        goto label_6;
      }
    }
    isChecked = this.btnEnableRobotPlacement.IsChecked;
    bool flag3 = true;
    num1 = isChecked.GetValueOrDefault() == flag3 & isChecked.HasValue ? 1 : 0;
label_6:
    bool flag4 = num1 != 0;
    this.AllJointsBlockExpander.IsEnabled = flag4;
    this.frameComboBoxCtrlHost.IsEnabled = flag4;
    this._frameComboBoxCtrl.Enabled = flag4;
    this.frameComboBoxCtrlHost.InvalidateVisual();
    if (!flag4)
      this.CoordinateReferenceBlock.IsExpanded = flag4;
    this.CoordinateReferenceBlock.IsEnabled = flag4;
    ((UIElement) this.txManManipulationControl).IsEnabled = flag4;
    if (!flag4)
    {
      this.txManManipulationControl.LinearValue = 0.0;
      this.txManManipulationControl.AngularValue = 0.0;
    }
    if (flag4)
    {
      if (flag1)
        this._manipulationLogic._isFreezed = true;
      CApRJRobotJogManipulationLogic manipulationLogic1 = this._manipulationLogic;
      isChecked = this.btnEnableRobotPlacement.IsChecked;
      int num2 = isChecked.Value ? 1 : 0;
      manipulationLogic1.EnableRobotPlacement = num2 != 0;
      this._manipulationLogic.MoveObjectsThatRobotIsAttachedTo = this.btnEnableRobotPlacement.SelectedItem == 1;
      CApRJRobotJogManipulationLogic manipulationLogic2 = this._manipulationLogic;
      isChecked = this.btnLockTCPF.IsChecked;
      int num3 = isChecked.Value ? 1 : 0;
      manipulationLogic2.LockTCPF = num3 != 0;
      if (!flag1)
        return;
      this.ReStoreFramesFromRobotInfo(this._manipulationLogic.Robot);
      this.txCoordinateReference.comboBoxFrameOfReference.SelectedIndex = this._robotsManager.ComboBoxFrameOfReferenceSelectedIndex;
    }
    else
    {
      CApRJRobotJogManipulationLogic manipulationLogic3 = this._manipulationLogic;
      isChecked = this.btnEnableRobotPlacement.IsChecked;
      int num4 = isChecked.Value ? 1 : 0;
      manipulationLogic3.EnableRobotPlacement = num4 != 0;
      this._manipulationLogic.MoveObjectsThatRobotIsAttachedTo = this.btnEnableRobotPlacement.SelectedItem == 1;
      CApRJRobotJogManipulationLogic manipulationLogic4 = this._manipulationLogic;
      isChecked = this.btnLockTCPF.IsChecked;
      int num5 = isChecked.Value ? 1 : 0;
      manipulationLogic4.LockTCPF = num5 != 0;
      this._manipulationLogic.UpdateMovingObjectForSlave();
    }
  }

  private void RefreshUiForRobot()
  {
    this.jointsBlock.IsEnabled = this.jointsBlock.JointsCount > 0;
    ((UIElement) this.btnEnableRobotPlacement).IsEnabled = this.btnLockTCPF.IsChecked.Value;
    bool? isChecked1 = this.btnLockTCPF.IsChecked;
    bool flag1 = false;
    int num;
    if (!(isChecked1.GetValueOrDefault() == flag1 & isChecked1.HasValue))
    {
      bool? isChecked2 = this.btnEnableRobotPlacement.IsChecked;
      bool flag2 = true;
      num = isChecked2.GetValueOrDefault() == flag2 & isChecked2.HasValue ? 1 : 0;
    }
    else
      num = 1;
    bool flag3 = num != 0;
    this.AllJointsBlockExpander.IsEnabled = flag3;
    if (!flag3)
      this.CoordinateReferenceBlock.IsExpanded = false;
    this.CoordinateReferenceBlock.IsEnabled = flag3;
    ((UIElement) this.txManManipulationControl).IsEnabled = flag3;
    if (!flag3)
      return;
    this._manipulationLogic.EnableRobotPlacement = this.btnEnableRobotPlacement.IsChecked.Value;
    this._manipulationLogic.MoveObjectsThatRobotIsAttachedTo = this.btnEnableRobotPlacement.SelectedItem == 1;
    this._manipulationLogic.LockTCPF = this.btnLockTCPF.IsChecked.Value;
  }

  public void btnLockTCPF_Click(object sender, RoutedEventArgs e)
  {
    this._manipulationLogic.LockTCPF = this.btnLockTCPF.IsChecked.Value;
    if (this.btnLockTCPF.IsChecked.Value)
      this.Notify(RJRobotJogResources.NotifyTCPLocked);
    else
      this.Notify(RJRobotJogResources.NotifyTCPUnlocked);
    bool? isChecked;
    if (this.CompoundEquipment != null)
    {
      CApRJSRobotsManager robotsManager = this._robotsManager;
      TxRobot robot = this._manipulationLogic.Robot;
      isChecked = this.btnLockTCPF.IsChecked;
      int num = isChecked.Value ? 1 : 0;
      robotsManager.UpdateRobotInfoLockTCPF(robot, num != 0);
    }
    isChecked = this.btnTeachLocation.IsChecked;
    bool flag = true;
    if (isChecked.GetValueOrDefault() == flag & isChecked.HasValue)
      this.TeachOneLocation();
    this._disableTCPFMovementByTcpfLockButton = true;
    this.SetExpandersState();
    this._disableTCPFMovementByTcpfLockButton = false;
    this.RefreshUI();
  }

  public void btnEnableRobotPlacement_Click(object sender, RoutedEventArgs e)
  {
    this._manipulationLogic.EnableRobotPlacement = this.btnEnableRobotPlacement.IsChecked.Value;
    if (this.CompoundEquipment != null)
      this._robotsManager.UpdateRobotInfoIsEnabledRobotPlacement(this._manipulationLogic.Robot, this.btnEnableRobotPlacement.IsChecked.Value);
    this.SetExpandersState();
    this.RefreshUI();
    if (this._manipulationLogic.EnableRobotPlacement)
    {
      if (this._manipulationLogic.MoveObjectsThatRobotIsAttachedTo)
        this.Notify(RJRobotJogResources.NotifyRobotPlacementWithAttachmentsON);
      else
        this.Notify(RJRobotJogResources.NotifyRobotPlacementON);
    }
    else
      this.Notify(RJRobotJogResources.NotifyRobotPlacementOFF);
  }

  private void SetExpandersState()
  {
    bool? isChecked1 = this.btnLockTCPF.IsChecked;
    bool flag1 = true;
    if (isChecked1.GetValueOrDefault() == flag1 & isChecked1.HasValue)
    {
      bool? isChecked2 = this.btnEnableRobotPlacement.IsChecked;
      bool flag2 = false;
      if (isChecked2.GetValueOrDefault() == flag2 & isChecked2.HasValue)
      {
        this.ManipulationExpander.IsExpanded = false;
        ((UIElement) this.txManManipulationControl).IsEnabled = false;
        this.frameComboBoxCtrlHost.IsEnabled = false;
        if (this._disableTCPFMovementByTcpfLockButton)
          this.ExternalJointsExpander.IsExpanded = true;
        this.AllJointsBlockExpander.IsEnabled = false;
        return;
      }
    }
    this.ManipulationExpander.IsExpanded = true;
    ((UIElement) this.txManManipulationControl).IsEnabled = true;
    if (!this.frameComboBoxCtrlHost.IsEnabled)
    {
      this.frameComboBoxCtrlHost.IsEnabled = true;
      this.frameComboBoxCtrlHost.InvalidateVisual();
    }
    this.ExternalJointsExpander.IsExpanded = false;
    this.AllJointsBlockExpander.IsExpanded = false;
    this.AllJointsBlockExpander.IsEnabled = true;
  }

  private void SetExpandersInitialState(bool isInitialLocationNotReached)
  {
    if (this._manipulationLogic.Location != null | isInitialLocationNotReached)
      this.LocationNavigationExpander.IsExpanded = true;
    bool? isChecked1 = this.btnLockTCPF.IsChecked;
    bool flag1 = true;
    if (isChecked1.GetValueOrDefault() == flag1 & isChecked1.HasValue)
    {
      bool? isChecked2 = this.btnEnableRobotPlacement.IsChecked;
      bool flag2 = false;
      if (isChecked2.GetValueOrDefault() == flag2 & isChecked2.HasValue)
      {
        this.ManipulationExpander.IsExpanded = false;
        ((UIElement) this.txManManipulationControl).IsEnabled = false;
        this.frameComboBoxCtrlHost.IsEnabled = false;
        this.ExternalJointsExpander.IsExpanded = true;
        this.AllJointsBlockExpander.IsExpanded = false;
        this.AllJointsBlockExpander.IsEnabled = false;
        return;
      }
    }
    this.ManipulationExpander.IsExpanded = true;
    ((UIElement) this.txManManipulationControl).IsEnabled = true;
    if (this.frameComboBoxCtrlHost.IsEnabled)
      return;
    this.frameComboBoxCtrlHost.IsEnabled = true;
    this.frameComboBoxCtrlHost.InvalidateVisual();
  }

  public void btnTeachLocation_Click(object sender, RoutedEventArgs e)
  {
    this._isTeachLocationClicked = true;
    try
    {
      this.TeachOneLocation();
      if (this._btnTeachLocationNumberOfClicks == 0)
      {
        ++this._btnTeachLocationNumberOfClicks;
        if (this.btnTeachLocation.IsChecked.Value)
        {
          this.btnTeachLocation.IsChecked = new bool?(false);
          this.Notify(string.Format(RJRobotJogResources.NotifyTeachLocation, (object) ((ITxObject) this.txLocationNavigationControl.Location).Name), clearAtNextNavigation: true);
        }
        else
          this.Notify(RJRobotJogResources.NotifyTeachModeOFF);
      }
      else if (this._btnTeachLocationNumberOfClicks == 1)
      {
        --this._btnTeachLocationNumberOfClicks;
        if (this.btnTeachLocation.IsChecked.Value)
        {
          this.btnTeachLocation.IsChecked = new bool?(false);
          this.Notify(string.Format(RJRobotJogResources.NotifyTeachLocation, (object) ((ITxObject) this.txLocationNavigationControl.Location).Name), clearAtNextNavigation: true);
        }
        else
          this.Notify(RJRobotJogResources.NotifyTeachModeOFF);
      }
      else
      {
        if (this._btnTeachLocationNumberOfClicks < 2)
          return;
        this._btnTeachLocationNumberOfClicks = 0;
        this.btnTeachLocation.IsChecked = new bool?(true);
        this.Notify(RJRobotJogResources.NotifyTeachModeON);
      }
    }
    finally
    {
      this._isTeachLocationClicked = false;
    }
  }

  private void btnTeachLocation_MouseDoubleClick(object sender, MouseButtonEventArgs e)
  {
  }

  public void btnClearTaughtLocation_Click(object sender, RoutedEventArgs e)
  {
    if (this.txLocationNavigationControl.Location is ITxRoboticLocationOperation location)
    {
      TxApplication.ActiveUndoManager.StartTransaction();
      this._manipulationLogic.IsManipulationFromInsideCommand = true;
      location.Teach((TxTransformation) null, (TxRobotConfigurationData) null);
      this._manipulationLogic.IsManipulationFromInsideCommand = false;
      TxApplication.ActiveUndoManager.EndTransaction();
      this.Notify(string.Format(RJRobotJogResources.NotifyTeachCleared, (object) ((ITxObject) location).Name), clearAtNextNavigation: true);
    }
    this._btnTeachLocationNumberOfClicks = 0;
    this.btnTeachLocation.IsChecked = new bool?(false);
  }

  private void btnSetExternalAxes_Click(object sender, RoutedEventArgs e)
  {
    this._manipulationLogic.SetRobotExternalAxisInLocation = this.btnSetExternalAxes.IsChecked.Value;
    this._manipulationLogic.IsManipulationFromInsideCommand = true;
    this._manipulationLogic.SetExternalAxes();
    this._manipulationLogic.IsManipulationFromInsideCommand = false;
    if (this._btnSetExternalValuesNumberOfClicks == 0)
    {
      ++this._btnSetExternalValuesNumberOfClicks;
      if (this.btnSetExternalAxes.IsChecked.Value)
      {
        this.btnSetExternalAxes.IsChecked = new bool?(false);
        this.Notify(string.Format(RJRobotJogResources.NotifyExternalAxesWereSet, (object) ((ITxObject) this.txLocationNavigationControl.Location).Name), clearAtNextNavigation: true);
      }
      else
        this.Notify(RJRobotJogResources.NotifyExternalAxesOFF);
    }
    else if (this._btnSetExternalValuesNumberOfClicks == 1)
    {
      --this._btnSetExternalValuesNumberOfClicks;
      if (this.btnSetExternalAxes.IsChecked.Value)
      {
        this.btnSetExternalAxes.IsChecked = new bool?(false);
        if (this._manipulationLogic.Location != null)
          this.Notify(string.Format(RJRobotJogResources.NotifyExternalAxesWereSet, (object) ((ITxObject) this._manipulationLogic.Location).Name), clearAtNextNavigation: true);
      }
      else
        this.Notify(RJRobotJogResources.NotifyExternalAxesOFF);
    }
    else if (this._btnSetExternalValuesNumberOfClicks >= 2)
    {
      this._btnSetExternalValuesNumberOfClicks = 0;
      this.btnSetExternalAxes.IsChecked = new bool?(true);
      this.Notify(RJRobotJogResources.NotifyExternalAxesON);
    }
    this._manipulationLogic.SetRobotExternalAxisInLocation = this.btnSetExternalAxes.IsChecked.Value;
  }

  private void btnSetExternalAxes_MouseDoubleClick(object sender, MouseButtonEventArgs e)
  {
    this._btnSetExternalValuesNumberOfClicks += 2;
  }

  private void btnClearExternalAxes_Click(object sender, RoutedEventArgs e)
  {
    if (this.txLocationNavigationControl.Location is ITxRoboticLocationOperation location)
    {
      this._manipulationLogic.IsManipulationFromInsideCommand = true;
      location.RobotExternalAxesData = (TxRobotExternalAxisData[]) null;
      this._manipulationLogic.IsManipulationFromInsideCommand = false;
      this.Notify(string.Format(RJRobotJogResources.NotifyExternalAxesCleared, (object) ((ITxObject) location).Name), clearAtNextNavigation: true);
    }
    this._btnSetExternalValuesNumberOfClicks = 0;
    this.btnSetExternalAxes.IsChecked = new bool?(false);
  }

  private void btnSettings_Click(object sender, RoutedEventArgs e)
  {
    CUiRJJointsOptionsForm jointsOptionsForm1 = new CUiRJJointsOptionsForm();
    ((Window) jointsOptionsForm1).Owner = (Window) this;
    CUiRJJointsOptionsForm jointsOptionsForm2 = jointsOptionsForm1;
    if (!jointsOptionsForm2.ShowDialog(CUiRJJointsOptionsForm.DeSerializeColumns(this.jointsBlock.RawColumnData)))
      return;
    this.jointsBlock.RawColumnData = CUiRJJointsOptionsForm.SerializeColumns(jointsOptionsForm2.Columns);
    this.jointsBlock.RefreshJoints();
    this._jointJogLogic.FireOptionsChanged(sender, jointsOptionsForm2.PrismaticStepSize, jointsOptionsForm2.RevoluteStepSize, jointsOptionsForm2.CustomSliderSensitivity);
    this.CopyAttachmentSetting = jointsOptionsForm2.CopyAttachment;
    this.DisplayGhostGun = jointsOptionsForm2.DisplayGhostGun;
    if (this.DisplayGhostGun)
    {
      bool? isChecked = this.btnFollowMode.IsChecked;
      bool flag = false;
      if (isChecked.GetValueOrDefault() == flag & isChecked.HasValue)
      {
        this._gunDisplayer.Show(this.txLocationNavigationControl.Location as ITxRoboticLocationOperation);
        goto label_5;
      }
    }
    this._gunDisplayer.Hide();
label_5:
    if (this.ManipulateSeamRoboticLocations != jointsOptionsForm2.ManipulateSeamRoboticLocations || this.ManipulateWeldRoboticLocations != jointsOptionsForm2.ManipulateWeldRoboticLocations)
    {
      this._manipulationLogic.UpdateTcpfMovability();
      this.ManipulateSeamRoboticLocations = jointsOptionsForm2.ManipulateSeamRoboticLocations;
      this.ManipulateWeldRoboticLocations = jointsOptionsForm2.ManipulateWeldRoboticLocations;
      this.NotifyFollowModeOn();
    }
    TxApplication.RefreshDisplay();
    TxWindowSettings.StoreWindowValue((TxWindow) this, "ColumnsData", (object) this.jointsBlock.RawColumnData);
  }

  private void btnShowDependentJoints_Click(object sender, RoutedEventArgs e)
  {
    this.jointsBlock.ShowDependentJoints = this.btnShowDependentJoints.IsChecked.Value;
    if (this.btnShowDependentJoints.IsChecked.Value)
      this.btnShowDependentJoints.ToolTip = (object) RJRobotJogResources.JointsOptions_HideDependentJoints;
    else
      this.btnShowDependentJoints.ToolTip = (object) RJRobotJogResources.JointsOptions_ShowDependentJoints;
  }

  private void btnResetToHardLimits_Click(object sender, RoutedEventArgs e)
  {
    this.jointsBlock.ResetToHardLimit((sender as System.Windows.Controls.Button).Tag as TxKinematicJointLimits);
    this.Notify(RJRobotJogResources.NotifyLimitsHard);
    TxApplication.RefreshDisplay();
  }

  private void btnResetAllSoftLimits_Click(object sender, RoutedEventArgs e)
  {
    this._jointJogLogic.ResetSoftLimits();
    this.Notify(RJRobotJogResources.NotifyLimitsSoft);
    TxApplication.RefreshDisplay();
  }

  public void SetCurrentRobot(TxRobot robot)
  {
    this.currentRobot.SelectObject((ITxObject) robot);
    this.CurrentRobot_SelectionChanged((object) this.currentRobot, (EventArgs) null);
  }

  public void SetMasterSlaveRole(string rule)
  {
    this.ddRobotMasterSlaveRole.SelectedItem = (object) rule;
  }

  public void SetMasterSlaveMode(bool status)
  {
    this.btnMasterSlaveMode.IsChecked = new bool?(status);
    this.btnMasterSlaveMode_Click((object) this.btnMasterSlaveMode, (RoutedEventArgs) null);
  }

  public void SetLockConfiguration(bool status)
  {
    this.btnLockConfiguration.IsChecked = new bool?(status);
  }

  public ITxRoboticLocationOperation GetLocationNavigationControlSelectedLocation()
  {
    return this.txLocationNavigationControl.Location as ITxRoboticLocationOperation;
  }

  public void AutoTestAddLocation(bool placement) => this.AddLocation(placement);

  internal void btnFollowMode_Click(object sender, RoutedEventArgs e)
  {
    if (this.btnFollowMode.IsChecked.Value)
    {
      if (this._manipulationLogic.IsTcpfMovable)
        this.NotifyFollowModeOn();
      else
        this.NotifyUnmovableTCPF();
    }
    else
      this.Notify(RJRobotJogResources.NotifyFollowModeOFF);
  }

  private void btnFollowMode_Checked(object sender, RoutedEventArgs e)
  {
    this._gunDisplayer.Hide();
    if (this.txLocationNavigationControl.Location == null)
      return;
    this._manipulationLogic.Location = this.txLocationNavigationControl.Location as ITxRoboticLocationOperation;
    TxApplication.RefreshDisplay();
  }

  private void btnFollowMode_Unchecked(object sender, RoutedEventArgs e)
  {
    this._manipulationLogic.Location = (ITxRoboticLocationOperation) null;
    if (this.DisplayGhostGun)
    {
      this._gunDisplayer.Show(this.txLocationNavigationControl.Location as ITxRoboticLocationOperation);
      TxApplication.RefreshDisplay();
    }
    this.Notify(RJRobotJogResources.NotifyFollowModeOFF);
  }

  private void btnFollowMode_PreviewMouseLeftButtonUp(object sender, MouseButtonEventArgs e)
  {
    bool? isChecked1 = this.btnFollowMode.IsChecked;
    bool flag1 = true;
    if (!(isChecked1.GetValueOrDefault() == flag1 & isChecked1.HasValue))
      return;
    bool? isChecked2 = this.btnTeachLocation.IsChecked;
    bool flag2 = true;
    if (!(isChecked2.GetValueOrDefault() == flag2 & isChecked2.HasValue))
      return;
    this.TeachOneLocation();
  }

  private void txLocationNavigationControl_LocationChanged(object sender, EventArgs e)
  {
    bool? nullable;
    if (this._clearNotificationAtNextLocationNavigation)
    {
      nullable = CUiRJRobotJogWindow.IsLocationAddedBefore;
      if (!nullable.HasValue)
      {
        this.NotifyClear();
        this._clearNotificationAtNextLocationNavigation = false;
      }
    }
    ITxRoboticLocationOperation location = this.txLocationNavigationControl.Location as ITxRoboticLocationOperation;
    if (this.DisplayGhostGun)
    {
      nullable = this.btnFollowMode.IsChecked;
      bool flag = false;
      if (nullable.GetValueOrDefault() == flag & nullable.HasValue)
        this._gunDisplayer.Show(location);
    }
    if (this.txLocationNavigationControl.Location != null && location == null)
    {
      this.Notify(RJRobotJogResources.NotifyInvalidLocationType);
      this.txLocationNavigationControl.Location = (ITxLocationOperation) null;
      this._clearNotificationAtNextLocationNavigation = true;
    }
    else
    {
      if (location != this._manipulationLogic.Location)
      {
        nullable = this.btnTeachLocation.IsChecked;
        bool flag = true;
        if (nullable.GetValueOrDefault() == flag & nullable.HasValue)
          this.TeachOneLocation();
      }
      if (location != null && this._manipulationLogic != null && TxRobot.op_Inequality(this._manipulationLogic.Robot, (ITxObject) null))
      {
        if (!CApRJRobotJogUtilities.IsRoboticLocationOperationWithAssignedRobot((ITxObject) location) || location.ParentRoboticOperation.Robot != this._manipulationLogic.Robot)
        {
          this.Notify(string.Format(RJRobotJogResources.LocationUnrelatedToRobotMessage, (object) ((ITxObject) location).Name, (object) ((TxBaseGeometryCreationObject) this._manipulationLogic.Robot).Name));
          this.txLocationNavigationControl.Location = (ITxLocationOperation) null;
          this._clearNotificationAtNextLocationNavigation = true;
          return;
        }
        if (this._prevLocationForNotification == null && this.txLocationNavigationControl.Location != null)
          this.NotifyLocationAndFollowModeState(this.txLocationNavigationControl.Location);
      }
      nullable = this.btnFollowMode.IsChecked;
      bool flag1 = true;
      if (nullable.GetValueOrDefault() == flag1 & nullable.HasValue)
      {
        this._manipulationLogic.Location = location;
        nullable = this.btnTeachLocation.IsChecked;
        bool flag2 = true;
        if (nullable.GetValueOrDefault() == flag2 & nullable.HasValue)
          this.TeachOneLocation();
      }
      this.txManManipulationControl.LinearValue = 0.0;
      this.txManManipulationControl.AngularValue = 0.0;
    }
  }

  private void ddlConfiguration_SelectionChanged(object sender, SelectionChangedEventArgs e)
  {
    bool? isChecked = this.btnTeachLocation.IsChecked;
    bool flag = true;
    if (!(isChecked.GetValueOrDefault() == flag & isChecked.HasValue))
      return;
    this.TeachOneLocation();
  }

  private void btnAddLocationBefore_Click(object sender, RoutedEventArgs e)
  {
    this.AddLocation(true);
  }

  private void btnAddLocationAfter_Click(object sender, RoutedEventArgs e) => this.AddLocation();

  private void AddLocation(bool isLocationAddedBefore = false)
  {
    if (!(this.txLocationNavigationControl.Location is ITxRoboticLocationOperation location) || location.ParentRoboticOperation == null)
    {
      this.Notify(RJRobotJogResources.NotifyAddLocationFailed);
    }
    else
    {
      ITxRoboticOrderedCompoundOperation roboticOperation = location.ParentRoboticOperation;
      this._addLocationSuccessFlag = false;
      try
      {
        this._manipulationLogic.IsManipulationFromInsideCommand = true;
        ((ITxObjectCollection) roboticOperation).ItemsAdded += new TxObjectCollection_ItemsAddedEventHandler(this.collection_ItemsAdded);
        CUiRJRobotJogWindow.IsLocationAddedBefore = new bool?(isLocationAddedBefore);
        TxApplication.ActiveUndoManager.StartTransaction();
        CApRJRobotJogUtilities.SetLocationAsActiveSelection((ITxLocationOperation) location);
        try
        {
          TxApplication.CommandsManager.ExecuteCommand(this.GetAddLocationExternalCommand());
        }
        catch
        {
          CUiRJRobotJogWindow.IsLocationAddedBefore = new bool?();
        }
        if (this._addLocationSuccessFlag && this._addedLocation != null)
        {
          this.Notify(this.CopyParametersAndAttachment(this._addedLocation), clearAtNextNavigation: true);
          bool? isChecked = this.btnFollowMode.IsChecked;
          bool flag = false;
          if (isChecked.GetValueOrDefault() == flag & isChecked.HasValue)
            this.TransformLocationToTCPF(this._addedLocation as ITxLocatableObject, (ITxLocatableObject) this._manipulationLogic.Robot.TCPF);
          this.txLocationNavigationControl.Location = (ITxLocationOperation) this._addedLocation;
        }
        else
          this.Notify(RJRobotJogResources.NotifyAddLocationFailed, (MessageType) 2);
      }
      finally
      {
        TxApplication.ActiveUndoManager.EndTransaction();
        CUiRJRobotJogWindow.IsLocationAddedBefore = new bool?();
        ((ITxObjectCollection) roboticOperation).ItemsAdded -= new TxObjectCollection_ItemsAddedEventHandler(this.collection_ItemsAdded);
        this._addedLocation = (ITxRoboticLocationOperation) null;
        this._manipulationLogic.IsManipulationFromInsideCommand = false;
      }
    }
  }

  internal string CopyParametersAndAttachment(ITxRoboticLocationOperation location)
  {
    this.CopyAttachmentToTheNewLocation(location);
    if (this.CopyParametersOption == CopyParametersOptions.None)
      return string.Format(RJRobotJogResources.NotifyAddLocationSucceeded, (object) ((ITxObject) location).Name);
    ITxRoboticLocationOperation referenceLocation = (ITxRoboticLocationOperation) null;
    this.CopyParametersToTheNewLocation(ref referenceLocation, location);
    return referenceLocation == null || ((ITxObject) referenceLocation).Name == null ? string.Format(RJRobotJogResources.NotifyAddLocationNoViaFoundSucceeded, (object) ((ITxObject) location).Name) : string.Format(RJRobotJogResources.NotifyAddLocationWithParametersSucceeded, (object) ((ITxObject) location).Name, (object) ((ITxObject) referenceLocation).Name);
  }

  private string GetAddLocationExternalCommand()
  {
    return CUiRJRobotJogWindow.IsLocationAddedBefore.Value ? "Path.AddLocationBefore" : "Path.AddLocationAfter";
  }

  private void CopyAttachmentToTheNewLocation(ITxRoboticLocationOperation newLocation)
  {
    if (!this.CopyAttachmentSetting)
      CApRJRobotJogUtilities.DetachRoboticLocationOperation(newLocation);
    else
      CApRJRobotJogUtilities.AttachTargetToSourceAttachment(this.FindOriginalLocation(newLocation), newLocation);
  }

  private void CopyParametersToTheNewLocation(
    ref ITxRoboticLocationOperation referenceLocation,
    ITxRoboticLocationOperation newLocation)
  {
    if (!this.FindReferenceLocation(ref referenceLocation, newLocation, typeof (TxRoboticViaLocationOperation)))
      return;
    switch (this.CopyParametersOption)
    {
      case CopyParametersOptions.Robotic:
        CApRJRobotJogUtilities.CopyParametersOnly(referenceLocation, newLocation);
        break;
      case CopyParametersOptions.RoboticAndOLP:
        CApRJRobotJogUtilities.CopyParametersAndOLP(referenceLocation, newLocation);
        break;
    }
  }

  private bool FindReferenceLocation(
    ref ITxRoboticLocationOperation viaToCopyFrom,
    ITxRoboticLocationOperation newLocation,
    Type type)
  {
    ITxRoboticLocationOperation locationOperation1 = (ITxRoboticLocationOperation) null;
    ITxOrderedCompoundOperation roboticOperation = newLocation.ParentRoboticOperation as ITxOrderedCompoundOperation;
    int indexOfChild = ((ITxOrderedObjectCollection) roboticOperation).GetIndexOfChild((ITxObject) newLocation);
    bool flag = type == typeof (TxRoboticViaLocationOperation);
    TxObjectList directDescendants = ((ITxObjectCollection) roboticOperation).GetDirectDescendants((ITxTypeFilter) new TxTypeFilter(typeof (ITxOperation)));
    for (int index = 0; index < ((Collection<ITxObject>) directDescendants).Count; ++index)
    {
      ITxRoboticLocationOperation locationOperation2 = !flag ? ((Collection<ITxObject>) directDescendants)[index] as ITxRoboticLocationOperation : (ITxRoboticLocationOperation) (((Collection<ITxObject>) directDescendants)[index] as TxRoboticViaLocationOperation);
      if (locationOperation2 != null)
      {
        if (index < indexOfChild)
          locationOperation1 = locationOperation2;
        else if (index != indexOfChild)
        {
          if (CUiRJRobotJogWindow.IsLocationAddedBefore.Value && index == indexOfChild + 1)
          {
            locationOperation1 = locationOperation2;
            break;
          }
          if (locationOperation1 == null && index > indexOfChild)
          {
            locationOperation1 = locationOperation2;
            break;
          }
          break;
        }
      }
    }
    if (locationOperation1 == null)
      return false;
    viaToCopyFrom = locationOperation1;
    return true;
  }

  private ITxRoboticLocationOperation FindOriginalLocation(ITxRoboticLocationOperation newLocation)
  {
    ITxOrderedCompoundOperation roboticOperation = newLocation.ParentRoboticOperation as ITxOrderedCompoundOperation;
    int indexOfChild = ((ITxOrderedObjectCollection) roboticOperation).GetIndexOfChild((ITxObject) newLocation);
    TxObjectList directDescendants1 = ((ITxObjectCollection) roboticOperation).GetDirectDescendants((ITxTypeFilter) new TxTypeFilter(typeof (ITxObject)));
    ITxObject originalLocation = !CUiRJRobotJogWindow.IsLocationAddedBefore.Value ? ((Collection<ITxObject>) directDescendants1)[indexOfChild - 1] : ((Collection<ITxObject>) directDescendants1)[indexOfChild + 1];
    if (!(originalLocation is TxRoboticSeamOperation))
      return originalLocation as ITxRoboticLocationOperation;
    TxObjectList directDescendants2 = (originalLocation as TxRoboticSeamOperation).GetDirectDescendants((ITxTypeFilter) new TxTypeFilter(typeof (ITxRoboticLocationOperation)));
    return ((Collection<ITxObject>) directDescendants2).Count > 0 ? ((Collection<ITxObject>) directDescendants2)[0] as ITxRoboticLocationOperation : (ITxRoboticLocationOperation) null;
  }

  private void collection_ItemsAdded(object sender, TxObjectCollection_ItemsAddedEventArgs args)
  {
    this._addLocationSuccessFlag = true;
    this._addedLocation = ((Collection<ITxObject>) args.Items)[0] as ITxRoboticLocationOperation;
  }

  private void TransformLocationToTCPF(ITxLocatableObject location, ITxLocatableObject tcpf)
  {
    location.Locate(tcpf.AbsoluteLocation);
  }

  private void RegisterJointLogicEvents()
  {
    if (this._jointJogLogic == null)
      return;
    this._jointJogLogic.SaveOldLocations += new Action(this._manipulationLogic.SaveOldLocations);
    this._jointJogLogic.JointValueChanged += new Func<TxJoint, bool>(this._manipulationLogic.JointJogManipulate);
    this._jointJogLogic.DeviceManipulatedFromInternalCommand += new Action<bool>(this._manipulationLogic.OnManipulationFromInternalCmd);
    this._jointJogLogic.LimitsControlsEntered += new CApRJRobotJogJointsLogic.CUiRJRobotJogJointLimitsControlsEnteredHandler(this._jointJogLogic_LimitsControlsEntered);
    this._jointJogLogic.LimitsControlsLeaved += new CApRJRobotJogJointsLogic.CUiRJRobotJogJointLimitsControlsLeavedHandler(this._jointJogLogic_LimitsControlsLeaved);
    this._jointJogLogic.BeforeJointValueChange += new CApRJRobotJogJointsLogic.CApRJRobotJogBeforeJointValueChangeHandler(this._jointJogLogic_BeforeJointValueChange);
    this._jointJogLogic.AfterJointValueChange += new CApRJRobotJogJointsLogic.CApRJRobotJogAfterJointValueChangeHandler(this._jointJogLogic_AfterJointValueChange);
  }

  private void UnregisterJointLogicEvents()
  {
    if (this._jointJogLogic == null)
      return;
    this._jointJogLogic.JointValueChanged -= new Func<TxJoint, bool>(this._manipulationLogic.JointJogManipulate);
    this._jointJogLogic.SaveOldLocations -= new Action(this._manipulationLogic.SaveOldLocations);
    this._jointJogLogic.DeviceManipulatedFromInternalCommand -= new Action<bool>(this._manipulationLogic.OnManipulationFromInternalCmd);
    this._jointJogLogic.LimitsControlsEntered -= new CApRJRobotJogJointsLogic.CUiRJRobotJogJointLimitsControlsEnteredHandler(this._jointJogLogic_LimitsControlsEntered);
    this._jointJogLogic.LimitsControlsLeaved -= new CApRJRobotJogJointsLogic.CUiRJRobotJogJointLimitsControlsLeavedHandler(this._jointJogLogic_LimitsControlsLeaved);
    this._jointJogLogic.BeforeJointValueChange -= new CApRJRobotJogJointsLogic.CApRJRobotJogBeforeJointValueChangeHandler(this._jointJogLogic_BeforeJointValueChange);
    this._jointJogLogic.AfterJointValueChange -= new CApRJRobotJogJointsLogic.CApRJRobotJogAfterJointValueChangeHandler(this._jointJogLogic_AfterJointValueChange);
  }

  private void TeachOneLocation()
  {
    if (this._manipulationLogic == null || this._manipulationLogic.Location == null)
      return;
    bool movedFromOutsideRj = this._manipulationLogic.IsMovedFromOutsideRJ;
    this._manipulationLogic.IsMovedFromOutsideRJ = false;
    TxApplication.ActiveUndoManager.StartTransaction();
    this._manipulationLogic.Location.Teach();
    TxApplication.ActiveUndoManager.EndTransaction();
    this._manipulationLogic.IsMovedFromOutsideRJ = movedFromOutsideRj;
    this._manipulationLogic.ChangeManipulatorReferenceFrame(this._manipulationLogic.ReferenceFrame, false);
  }

  private void Notify(string msg, MessageType messageType = 1, bool clearAtNextNavigation = false)
  {
    if (!this.LocationNavigationExpander.IsExpanded)
      return;
    ((ContentControl) this.warningMessageBar).Content = (object) msg;
    this.warningMessageBar.MessageType = messageType;
    ((UIElement) this.warningMessageBar).Visibility = Visibility.Visible;
    this._clearNotificationAtNextLocationNavigation = clearAtNextNavigation;
  }

  private void NotifyClear()
  {
    ((ContentControl) this.warningMessageBar).Content = (object) string.Empty;
    ((UIElement) this.warningMessageBar).Visibility = Visibility.Collapsed;
  }

  private void NotifyUnmovableTCPF()
  {
    if (this._manipulationLogic.IsTcpfMovable)
      return;
    this.Notify(string.Format(RJRobotJogResources.NotifyCannotMoveLocationType, (object) ((ITxObject) this._manipulationLogic.Location).Name), clearAtNextNavigation: true);
  }

  private void NotifyFollowModeOn()
  {
    if (!this._manipulationLogic.IsTcpfMovable || this._manipulationLogic.Location == null)
      return;
    this.Notify(RJRobotJogResources.NotifyFollowModeON);
  }

  private void NotifyLocationAndFollowModeState(ITxLocationOperation loc)
  {
    if (loc == null || ((ITxObject) loc).Name == null)
      return;
    bool? isChecked = this.btnFollowMode.IsChecked;
    bool flag = true;
    if (isChecked.GetValueOrDefault() == flag & isChecked.HasValue)
      this.Notify(string.Format(RJRobotJogResources.NotifySelectLocationFollowModeOn, (object) ((ITxObject) loc).Name), clearAtNextNavigation: true);
    else
      this.Notify(string.Format(RJRobotJogResources.NotifySelectLocationFollowModeOff, (object) ((ITxObject) loc).Name), clearAtNextNavigation: true);
    this._prevLocationForNotification = loc;
  }

  private void txManManipulationControl_RepeatDeltaChangeEnded(object sender, EventArgs e)
  {
    if (!this.m_continuousTransactionRunning)
      return;
    TxApplication.ActiveUndoManager.EndTransaction();
    this.m_continuousTransactionRunning = false;
  }

  private void txManManipulationControl_RepeatDeltaChangeStarted(object sender, EventArgs e)
  {
    if (this.m_continuousTransactionRunning)
      return;
    TxApplication.ActiveUndoManager.StartTransaction();
    this.m_continuousTransactionRunning = true;
  }

  private void btnMoveToTCPF_Click(object sender, RoutedEventArgs e)
  {
    this._manipulationLogic.MoveLocationToTCPF(this.txLocationNavigationControl.Location as ITxRoboticLocationOperation);
  }

  private void TxWindow_ContentRendered(object sender, EventArgs e)
  {
  }

  [DebuggerNonUserCode]
  [GeneratedCode("PresentationBuildTasks", "4.0.0.0")]
  public void InitializeComponent()
  {
    if (this._contentLoaded)
      return;
    this._contentLoaded = true;
    System.Windows.Application.LoadComponent((object) this, new Uri("/DnProcessSimulateCommands;component/robotjog/cuirjrobotjogwindow.xaml", UriKind.Relative));
  }

  [DebuggerNonUserCode]
  [GeneratedCode("PresentationBuildTasks", "4.0.0.0")]
  internal Delegate _CreateDelegate(Type delegateType, string handler)
  {
    return Delegate.CreateDelegate(delegateType, (object) this, handler);
  }

  [DebuggerNonUserCode]
  [GeneratedCode("PresentationBuildTasks", "4.0.0.0")]
  [EditorBrowsable(EditorBrowsableState.Never)]
  void IComponentConnector.Connect(int connectionId, object target)
  {
    switch (connectionId)
    {
      case 1:
        ((FrameworkElement) target).Loaded += new RoutedEventHandler(this.TxWindow_Loaded);
        ((Window) target).ContentRendered += new EventHandler(this.TxWindow_ContentRendered);
        ((UIElement) target).PreviewMouseDown += new MouseButtonEventHandler(this.TxWindow_PreviewMouseDown);
        break;
      case 2:
        this.m_compoundPanel = (Grid) target;
        break;
      case 3:
        this.currentRobot = (TxObjectComboBoxCotrol) target;
        this.currentRobot.SelectionChanged += new EventHandler(this.CurrentRobot_SelectionChanged);
        this.currentRobot.Picked += new TxObjComboBoxCtrl_PickedEventHandler(this.CurrentRobot_SelectionChanged);
        break;
      case 4:
        this.ddRobotMasterSlaveRole = (System.Windows.Controls.ComboBox) target;
        this.ddRobotMasterSlaveRole.SelectionChanged += new SelectionChangedEventHandler(this.ddRobotMasterSlaveRole_SelectionChanged);
        break;
      case 5:
        this.btnLockTCPF = (ToggleButton) target;
        this.btnLockTCPF.Click += new RoutedEventHandler(this.btnLockTCPF_Click);
        break;
      case 6:
        this.btnLockTCPF_img = (System.Windows.Controls.Image) target;
        break;
      case 7:
        this.btnEnableRobotPlacement = (TxToolbarSplitButton) target;
        this.btnEnableRobotPlacement.Click += new RoutedEventHandler(this.btnEnableRobotPlacement_Click);
        break;
      case 8:
        this.btnShowDependentJoints = (ToggleButton) target;
        this.btnShowDependentJoints.Click += new RoutedEventHandler(this.btnShowDependentJoints_Click);
        break;
      case 9:
        this.btnShowDependentJoints_img = (System.Windows.Controls.Image) target;
        break;
      case 10:
        this.btnResetToHardLimits = (System.Windows.Controls.Button) target;
        this.btnResetToHardLimits.Click += new RoutedEventHandler(this.btnResetToHardLimits_Click);
        break;
      case 11:
        this.btnResetToHardLimits_img = (System.Windows.Controls.Image) target;
        break;
      case 12:
        this.btnResetAllSoftLimits = (System.Windows.Controls.Button) target;
        this.btnResetAllSoftLimits.Click += new RoutedEventHandler(this.btnResetAllSoftLimits_Click);
        break;
      case 13:
        this.btnResetAllSoftLimits_img = (System.Windows.Controls.Image) target;
        break;
      case 14:
        this.btnSetExternalAxes = (ToggleButton) target;
        this.btnSetExternalAxes.Click += new RoutedEventHandler(this.btnSetExternalAxes_Click);
        this.btnSetExternalAxes.MouseDoubleClick += new MouseButtonEventHandler(this.btnSetExternalAxes_MouseDoubleClick);
        break;
      case 15:
        this.btnSetExternalAxes_img = (System.Windows.Controls.Image) target;
        break;
      case 16 /*0x10*/:
        this.btnClearExternalAxes = (System.Windows.Controls.Button) target;
        this.btnClearExternalAxes.Click += new RoutedEventHandler(this.btnClearExternalAxes_Click);
        break;
      case 17:
        this.btnClearExternalAxes_img = (System.Windows.Controls.Image) target;
        break;
      case 18:
        this.btnTeachLocation = (ToggleButton) target;
        this.btnTeachLocation.Click += new RoutedEventHandler(this.btnTeachLocation_Click);
        this.btnTeachLocation.MouseDoubleClick += new MouseButtonEventHandler(this.btnTeachLocation_MouseDoubleClick);
        break;
      case 19:
        this.btnTeachLocation_img = (System.Windows.Controls.Image) target;
        break;
      case 20:
        this.btnClearTaughtLocation = (System.Windows.Controls.Button) target;
        this.btnClearTaughtLocation.Click += new RoutedEventHandler(this.btnClearTaughtLocation_Click);
        break;
      case 21:
        this.btnClearTaughtLocation_img = (System.Windows.Controls.Image) target;
        break;
      case 22:
        this.btnMoveToTCPF = (System.Windows.Controls.Button) target;
        this.btnMoveToTCPF.Click += new RoutedEventHandler(this.btnMoveToTCPF_Click);
        break;
      case 23:
        this.btnMoveToTCPF_img = (System.Windows.Controls.Image) target;
        break;
      case 24:
        this.btnOptions = (System.Windows.Controls.Button) target;
        this.btnOptions.Click += new RoutedEventHandler(this.btnSettings_Click);
        break;
      case 25:
        this.btnOptions_img = (System.Windows.Controls.Image) target;
        break;
      case 26:
        this.btnMasterSlaveMode = (ToggleButton) target;
        this.btnMasterSlaveMode.Click += new RoutedEventHandler(this.btnMasterSlaveMode_Click);
        break;
      case 27:
        this.btnMasterSlaveMode_img = (System.Windows.Controls.Image) target;
        break;
      case 28:
        this.LocationNavigationExpander = (Expander) target;
        this.LocationNavigationExpander.Collapsed += new RoutedEventHandler(this.LocationNavigationExpander_Collapsed);
        this.LocationNavigationExpander.SizeChanged += new SizeChangedEventHandler(this.ExpanderBlock_SizeChanged);
        break;
      case 29:
        this.txLocationNavigationControl = (UiInternalControls.WPFControls.TxLocationNavigationControl.TxLocationNavigationControl) target;
        this.txLocationNavigationControl.LocationChanged += new EventHandler(this.txLocationNavigationControl_LocationChanged);
        break;
      case 30:
        this.btnFollowMode = (ToggleButton) target;
        this.btnFollowMode.Checked += new RoutedEventHandler(this.btnFollowMode_Checked);
        this.btnFollowMode.Click += new RoutedEventHandler(this.btnFollowMode_Click);
        this.btnFollowMode.Unchecked += new RoutedEventHandler(this.btnFollowMode_Unchecked);
        this.btnFollowMode.PreviewMouseLeftButtonUp += new MouseButtonEventHandler(this.btnFollowMode_PreviewMouseLeftButtonUp);
        break;
      case 31 /*0x1F*/:
        this.btnFollowMode_img = (System.Windows.Controls.Image) target;
        break;
      case 32 /*0x20*/:
        this.btnAddLocationBefore = (System.Windows.Controls.Button) target;
        this.btnAddLocationBefore.Click += new RoutedEventHandler(this.btnAddLocationBefore_Click);
        break;
      case 33:
        this.btnAddLocationBefore_img = (System.Windows.Controls.Image) target;
        break;
      case 34:
        this.btnAddLocationAfter = (System.Windows.Controls.Button) target;
        this.btnAddLocationAfter.Click += new RoutedEventHandler(this.btnAddLocationAfter_Click);
        break;
      case 35:
        this.btnAddLocationAfter_img = (System.Windows.Controls.Image) target;
        break;
      case 36:
        this.comboCopyParameters = (System.Windows.Controls.ComboBox) target;
        break;
      case 37:
        this.warningMessageBar = (TxMessageBar) target;
        break;
      case 38:
        this.ManipulationExpander = (Expander) target;
        this.ManipulationExpander.SizeChanged += new SizeChangedEventHandler(this.ExpanderBlock_SizeChanged);
        break;
      case 39:
        this.txManManipulationControl = (TxPlacementCollisionControl) target;
        // ISSUE: method pointer
        this.txManManipulationControl.DeltaChanged += new TxPlacementCollisionControl.TxPlacementCollisionControlDeltaChangedEventHanlder((object) this, __methodptr(txManManipulationControl_DeltaChanged));
        this.txManManipulationControl.RunToCollision += new TxPlacementCollisionControl.TxPlacementCollisionControlRunCollisionEventHandler(this.txManManipulationControl_RunToCollision);
        // ISSUE: method pointer
        this.txManManipulationControl.MovementTypeChanged += new TxPlacementCollisionControl.TxPlacementCollisionControlMovementTypeChangedEventHanlder((object) this, __methodptr(txManManipulationControl_MovementTypeChanged));
        this.txManManipulationControl.RepeatDeltaChangeEnded += new EventHandler(this.txManManipulationControl_RepeatDeltaChangeEnded);
        this.txManManipulationControl.RepeatDeltaChangeStarted += new EventHandler(this.txManManipulationControl_RepeatDeltaChangeStarted);
        break;
      case 40:
        this.frameComboBoxCtrlHost = (WindowsFormsHost) target;
        break;
      case 41:
        this.lblConfigurationCaption = (TextBlock) target;
        break;
      case 42:
        this.ddlConfiguration = (System.Windows.Controls.ComboBox) target;
        this.ddlConfiguration.SelectionChanged += new SelectionChangedEventHandler(this.ddlConfiguration_SelectionChanged);
        this.ddlConfiguration.DropDownOpened += new EventHandler(this.ddlConfiguration_DropDownOpened);
        break;
      case 43:
        this.btnLockConfiguration = (ToggleButton) target;
        this.btnLockConfiguration.Click += new RoutedEventHandler(this.btnLockConfiguration_Click);
        break;
      case 44:
        this.btnLock_img = (System.Windows.Controls.Image) target;
        break;
      case 45:
        this.ExternalJointsExpander = (Expander) target;
        this.ExternalJointsExpander.Expanded += new RoutedEventHandler(this.JointsExpanderHasExpanded);
        this.ExternalJointsExpander.SizeChanged += new SizeChangedEventHandler(this.ExpanderBlock_SizeChanged);
        break;
      case 46:
        this.jointsBlock = (CUiJointsControl) target;
        break;
      case 47:
        this.AllJointsBlockExpander = (Expander) target;
        this.AllJointsBlockExpander.Expanded += new RoutedEventHandler(this.JointsExpanderHasExpanded);
        this.AllJointsBlockExpander.SizeChanged += new SizeChangedEventHandler(this.ExpanderBlock_SizeChanged);
        break;
      case 48 /*0x30*/:
        this.CoordinateReferenceBlock = (Expander) target;
        this.CoordinateReferenceBlock.SizeChanged += new SizeChangedEventHandler(this.ExpanderBlock_SizeChanged);
        break;
      case 49:
        this.txCoordinateReference = (CUiCoordinateReference) target;
        break;
      case 50:
        this.btnReset = (System.Windows.Controls.Button) target;
        this.btnReset.Click += new RoutedEventHandler(this.btnReset_Click);
        break;
      case 51:
        this.btnClose = (System.Windows.Controls.Button) target;
        this.btnClose.Click += new RoutedEventHandler(this.btnClose_Click);
        break;
      default:
        this._contentLoaded = true;
        break;
    }
  }
}
